To find, copy the corresponding value, paste

Closed
aishu - Nov 12, 2011 at 02:43 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Nov 12, 2011 at 10:05 PM
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 June 14, 2009 Status Contributor Last seen August 7, 2021 811
Nov 12, 2011 at 10:05 PM
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
0