To find, copy the corresponding value, paste

Closed
aishu - 12 Nov 2011 à 02:43
venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 - 12 Nov 2011 à 22:05
Hello,
i want the macro code for finding a value using inputbox, copy its corresponding value(row) and paste them in the same sheet where the cell pointer is kept. can you suggest it, please.



1 response

venkat1926 Posts 1863 Registration date Sunday 14 June 2009 Status Contributor Last seen 7 August 2021 811
12 Nov 2011 à 22:05
before running this macro select any cell with aleast one row and one column between the main data and the selection.
for e.g. the main data from A1 to B6 do not select cell in row no.7 or column C.
main data is like this
a 1
s 2
d 3
f 4
g 5
h 6

the cursor is kept (in other words select) cell A13

now run the macro


Sub test()
Dim r As Range, cfind As Range, x
Set r = Range("a1").CurrentRegion
x = InputBox("the string or number you require for e.g. s")
Set cfind = r.Find(what:=x, lookat:=xlWhole)
If Not cfind Is Nothing Then
cfind.EntireRow.Copy Selection
End If
End Sub