• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

How to Check String in top row of active column

I am a new to VBA (fun!) and am trying to write code that determines if the top cell (on row 5) of  the active column  contains a specific string.  e.g. "Sun".  I understand how to use the intstr, but cannot figure out how to change the range/cell reference in the bracket to reflect a different column.  Thanks for any advice at all!!!

 If InStr(1, [b5], "Sun", vbTextCompare) > 0 Then
MsgBox "It is Sunday."
Else
MsgBox "It is not Sunday"
End If
0
Not2ruthless
Asked:
Not2ruthless
1 Solution
 
jimyXCommented:
I do not use VBA but I know you can use COLUMN() to retrieve the current column.
0
 
Patrick MatthewsCommented:
To test Row 5 for the "active column":

If InStr(1, Cells(5, ActiveCell.Column), "Sun", vbTextCompare) > 0 Then

Open in new window


BTW, nice going on remembering the vbTextCompare.  Most people forget that VBA's default for text comparisons is case-sensitive :)
0
 
Not2ruthlessAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now