ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do i create a macro using copy (https://www.excelbanter.com/excel-programming/443012-how-do-i-create-macro-using-copy.html)

AndrewT

How do i create a macro using copy
 
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

Jacob Skaria

How do i create a macro using copy
 
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


AndrewT

How do i create a macro using copy
 
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


Jacob Skaria

How do i create a macro using copy
 
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



All times are GMT +1. The time now is 09:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com