How do i create a macro using copy

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
 
J

Jacob Skaria

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
 
J

Jacob Skaria

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top