How do i create a macro using copy

  • Follow


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
0
Reply Utf 6/2/2010 8:22:07 AM

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

-- 
Jacob (MVP - Excel)


"AndrewT" wrote:

> 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
0
Reply Utf 6/2/2010 9:04:01 AM


Thanks. 
But is there a way for me input it using the inputbox for search?

"Jacob Skaria" wrote:

> 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
> 
> -- 
> Jacob (MVP - Excel)
> 
> 
> "AndrewT" wrote:
> 
> > 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
0
Reply Utf 6/2/2010 9:48:06 AM

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



-- 
Jacob (MVP - Excel)


"AndrewT" wrote:

> Thanks. 
> But is there a way for me input it using the inputbox for search?
> 
> "Jacob Skaria" wrote:
> 
> > 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
> > 
> > -- 
> > Jacob (MVP - Excel)
> > 
> > 
> > "AndrewT" wrote:
> > 
> > > 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
0
Reply Utf 6/2/2010 9:54:01 AM

3 Replies
157 Views

(page loaded in 0.076 seconds)


Reply: