How do i create a macro using copy

  • Thread starter Thread starter AndrewT
  • Start date Start date
A

AndrewT

Hi,

I would like to know how do i create a macro the will copy what i have in
cell A1 or inputbox and search it for me.

Eg. Cell A1 consist of text "Apple"

when click on the button, it will find Apple.
If it is "Orange" it will find orange.

I do remember creating it once but have forget about it.

Any advise.

Thanks
 
Try

Sub Macro()

Dim varFound As Variant, varSearch As Variant

varSearch = Range("A1")

Set varFound = Cells.Find(varSearch, _
After:=Range("A1"), LookIn:=xlValues, lookat:=xlWhole)
If varFound.Address <> "$A$1" Then
varFound.Select
Else
MsgBox "Search string '" & Range("A1") & "' could not be found"
End If

End Sub
 
Try

Sub Macro()

Dim varFound As Variant, varSearch As Variant

varSearch = InputBox("Enter search string")

Set varFound = Cells.Find(varSearch, , xlValues, xlWhole)
If Not varFound Is Nothing Then
varFound.Select
Else
MsgBox "Search string '" & varSearch & "' could not be found"
End If

End Sub
 
Back
Top