syntax question - cell references in VB code

N

needyourhelp

Given the following code (found on this site..)

With ActiveSheet.Range("B:B")
Set FoundCell = .Find(what:="whatever", _
after:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
End With

How do I tell VB to look in Cell H1 for the what:="whatever" ?

ie. I want to use the value found in the Cell H1 not the text "whatever"

I've tried every combination of H1, H1:H1, $H1, Range(H1), Range(H1:H1),
Range("H1"),etc....

All generate compile errors, syntax errors, or runtime errors....

Forgive the simple question, but I'm not VB literate and I don't have a
manual handy.
 
J

JE McGimpsey

One way:

With ActiveSheet.Range("B:B")
Set FoundCell = .Find(What:=ActiveSheet.Range("H1").Value, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
 

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