Excel匹配单元格时返回整行
我有两张工作簿。
工作表1包含所有的数据。
工作表2目前是空白的,我打算使用VLOOKUP来返回任何匹配特定单元格的行。
在E列中的表1中,每个单元格中都有不同的值,我想返回任何表示tyre
我希望他们在E列包含单词轮胎时复制整行数据。 单词轮胎在Sheet2的单元格B1中
我目前已经在表2中试过这个代码,但只是获得了#VALUE! 错误。
=VLOOKUP($B$1,'sheet1'!E:E,0,FALSE)
我宁愿使用VBA方法。 只要运行一个macros说:
Public Sub specialLookUp() Dim keyword As String: keyword = Sheets("sheet2").Range("B1").Value Dim countRows1 As Long, countRows2 As Long countRows1 = 2 'the first row of your dataset in sheet1 endRows1 = 1000 'the last row of your dataset in sheet1 countRows2 = 2 'the first row where you want to start writing the found rows For j = countRows1 To endRows1 If Sheets("sheet1").Range("E" & j).Value = keyword Then Sheets("sheet2").Rows(countRows2).Value = Sheets("sheet1").Rows(j).Value countRows2 = countRows2 + 1 End If Next j End Sub
请注意,现在您可以在sheet1中对数据集的开始和结束进行硬编码,因为您告诉我您的数据没有ID或任何types的必填字段。