简体   繁体   English

在列中搜索一个值,并使用获得的行号来复制一个单元格

[英]Search for a value in a column and use the row number obtained to copy a cell

I have been trying to search for a value in a column and using the row number obtained I want copy a cell.我一直在尝试在列中搜索一个值并使用获得的行号来复制一个单元格。 Here's my code.这是我的代码。

If Trim(FindString) <> "" Then
    With Sheets("Details").Range("A:A") 'searches all of column A
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        x = Rng.Row
        If Not Rng Is Nothing Then
            Sheets("Details").Activate
            Sheets("Details").Range("Hx").Copy
            Sheets("Report").Activate
            .Range("A6").PasteSpecial xlPasteFormats
        Else
            MsgBox "Unique ID Doesnot Exist! Please Check Again." 'value not found
        End If
    End With
End If

How to get the value of x and refer to the cell in column H with the row number obtained from the search?如何获取 x 的值并使用从搜索中获得的行号引用 H 列中的单元格?

Thanks谢谢

To close the question: variables don't belong inside quotes.结束这个问题:变量不属于引号内。 Concatenate with & :&连接:

Sheets("Details").Range("H" & x).Copy

Also, you need to move the x = Rng.Row after the If Not Rng Is Nothing Then .此外,您需要在If Not Rng Is Nothing Then之后移动x = Rng.Row

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用单元格值作为行号和列号 - Use a cell value as Row and Column number 搜索列中的每个单元格以查找特定值,并从该值所在的行中的另一个单元格复制值 - Search each cell in a column to find a certain value and copy value from another cell in the row the value is found in 搜索一个单元格中的数字,然后将一个单元格从该行复制到另一个单元格 - Search for the number in a cell then copy a cell from that row to another cell 将单元格值复制并粘贴到列的最后一行 - Copy and paste a cell value on the last row of a column 在列中搜索值并将行复制到新工作表 - Search for a value in a column and copy row to new sheet 使用行号和列号更新单元格值,以根据选择的单元格在间接函数中使用 - Update a cell value with Row and Column number for use in indirect function based on which cell is selected 查找具有列最大值的单元格,复制整个行并粘贴到第2行 - Find cell with max value of column, copy entire row and paste in row 2 搜索工作簿中的单元格值并复制整个行和标题 - Search workbook for cell value and copy entire row and headers Excel - 在一行中搜索特定文本,然后将该值复制并粘贴到特定单元格中 - Excel - search for specific text in a row then copy and paste that value into a specific cell 复制/粘贴行 n 次(根据单元格中的值) - copy/paste row n number of times (according to value from cell)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM