[英]Excel Return Whole row when it Matches Cell
I have a workbook with two sheets. 我有一本有两张纸的工作簿。
Sheet 1 has all of the data. 表格1包含所有数据。
Sheet 2 is currently blank and I am planning to use a VLOOKUP to return any row that matches the certain cell. 工作表2当前为空白,我计划使用VLOOKUP返回与特定单元格匹配的任何行。
In sheet 1 in column E there are different values in each cell, I want to return any that say tyre
在E列的工作表1中,每个单元格中都有不同的值,我想返回任何表示tyre
I want them to copy the whole row of data whenever column E contains the word tyre. 我希望他们在E列包含“轮胎”一词时复制整行数据。 The word tyre is in Cell B1 in Sheet2 轮胎一词在Sheet2的单元格B1中
I have currently tried this code which is in sheet 2 but just getting a #VALUE! 我目前已经尝试了此代码,该代码位于工作表2中,但仅获得#VALUE! error. 错误。
=VLOOKUP($B$1,'sheet1'!E:E,0,FALSE)
I would rather use a VBA approach. 我宁愿使用VBA方法。 Just run a macro which says: 只需运行一个宏,上面写着:
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
Please note that now you can hardcode the beginning and the end of your dataset in sheet1, since you've told me your data have not an ID or any kind of field which is mandatory. 请注意,由于您已经告诉我您的数据没有ID或任何必填字段,因此现在您可以在sheet1中将数据集的开头和结尾进行硬编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.