"FIND" Macro

jamieleeuk

Board Regular
Joined
Feb 9, 2009
Messages
99
Hi,

I have recorded the following code by doing CTRL+F, entering a search string and pressing Find.

Sub test()
' Cells.Find(What:=***THE VALUE IN CELL W3***, After:=ActiveCell, LookIn:=xlFormulas, LookAt
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
End Sub

Please can someone let me know what I need to put in place of the above ***THE VALUE IN CELL W3*** to enable a user to enter a search string in cell W3 and for it (if a matching value found) for it to become the active cell?

thanks in advance
Jamie
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try

Code:
Sub test()
Dim Found As Range
Set Found = Cells.Find(What:=Range("W3").Value, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not Found Is Nothing Then Found.Select
End Sub
 
Upvote 0
Thanks Peter,

Whereas I don't receive any errors, the active cell doesn't appear to change to the cell that is Found.
Maybe a better way for me to see if there's a match is if the matched value could somehow change colour?

IE, if value in W3 is found elsewhere on the sheet, then highlight the value in its place?

Is that possible?
 
Upvote 0
See if this works

Code:
Sub test()
Dim Found As Range
Set Found = Cells.Find(What:=Range("W3").Value, LookIn:=xlValues, LookAt:=xlPart)
If Found Is Nothing Then
    MsgBox "Not found", vbExclamation
Else
    Found.Interior.ColorIndex = 6
End If
End Sub
 
Upvote 0
Peter. thanks.

It's almost there and from whats on the code already, I think I'll be able to finish it off.

Thanks again
Jamie
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,487
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top