简体   繁体   English

匹配单元格时Excel返回整行

[英]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.

相关问题 当列单元格仅使用公式匹配值时,Excel将返回整行 - Excel return whole row when column cell matches value using formula only Excel:如果单元格中的值与另一个选项卡上的列中的值匹配,我如何返回空白行上方的特定单元格? - Excel: If a value in a cell matches a value in a column on another tab, how can I return a specific cell above a blank row? 如果其他单元格与列匹配,则Excel计算行中的某些单元格范围 - Excel counting certain cell range in row if other cell matches column 如果文本框值与 Excel VBA 中的单元格值匹配,如何更新行 - How to update a row if textbox value matches with a cell value in Excel VBA Excel:如果行中的单元格与字符串匹配,我想对前两个值求和 - Excel: I want to SUM the top 2 values IF a cell in the row matches a string Excel:如果单元格与列名称匹配,则返回列中的所有值 - Excel: Return all values in a column if a cell matches the column name Excel:在进行部分匹配时在单个单元格中返回多个匹配项 - Excel: Return multiple matches in a single cell while doing a partial match 在Excel的整行中计算同一单元格中的多个值 - Count multiple values in Same Cell, within whole Row in Excel Excel VBA如果单元格包含整个工作簿中的文本,则删除一行 - Excel vba Deleting a row if a cell contains a text throughout whole workbook Excel - 如果单元格包含特定文本,则将整行移动到下一个工作表中 - Excel - move a whole row into the next worksheet if cell contains specific text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM