-
Find a word
Is there a way to replicate the Control F function within VBA?
right now I am using this but it is not very flexible. It looks for the word "Time" in column A, is it possible for it to look in both column A and B?
[VBA]
FindTime = Application.WorksheetFunction.Match("time", RngA, 0)
[/VBA]
-
Record a macro while doing the search. That will give you the basic code. If you need to modify it further, let us know.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
I have tried that but nothing gets recorded.
-
I've not known the recorder to fail with such. Where does it suggest the code is being saved?
Anyway, here is recorded code, and how it might be tidied up
[VBA]
Option Explicit
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("A:B").Select
Selection.Find(What:="Time", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("C25").Select
End Sub
Sub Refined()
Dim Rng as Range
Set Rng = Columns("A:B").Find(What:="Time", LookIn:=xlFormulas, _
LookAt:=xlWhole)
Rng.Interior.ColorIndex = 6
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
thank you, that worked great.
I've tried on a couple of occassions and nothing was recorded when using Control + F, I just tried it again and it did record. Maybe I goofed on the other occassions, or maybe it was some glitch.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules