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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.