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