Find specific string in range of cells

  • Thread starter Thread starter Ian
  • Start date Start date
I

Ian

I am trying to "future-proof" some code.

I currently have some code which returns the first and last dates in a
specific column. This is fine, except that the column may change (was A, is
now B, may change again).

I have to modify the code as it is currently specific to column A.

What is the easiest way to fing the column with Date in row 1? I know I can
specify a range (eg A1:G1) then loop through to match the string, but is
there a better way?
 
something like this

Dim rngDate As Range

Set rngDate = Range("A1:G1").Find(What:="Date", _
LookAt:=xlWhole, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngDate Is Nothing Then
MsgBox "Date was not found"
Else
MsgBox rngDate.Address
'your code here
End If
 
I only needed the column number so changing rngDate.Address to
rngDate.Column got me sorted.

Thanks for your help. I knew there had to be an easier way :-)
 

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

Back
Top