To return the column number of a string

  • Thread starter Thread starter prasanna.janardhana
  • Start date Start date
P

prasanna.janardhana

Hello All,
I am pretty new to Excel Macros. I was writing a code and stuck up
with this problem.
I want to write the code to return the column number of a particular
string.
Like, I have "VET" string in one of the cells, A20

My code has to return to the column number 1 for the string "VET"

Please help,
Thanks,
Prasanna.
 
Prasanna
Try these

Sub getcell()
For Each c In Selection
If c = "VET" Then
MsgBox "Cell " & c.Address & " Contains VET."
End If
Next
End Sub

Sub getcell2()
For Each c In Selection
If c = "VET" Then
MsgBox "Column " & c.Column & " Contains VET."
End If
Next
End Sub

Regards
Peter
 
or you do not have to select the range, see this

Sub getCell3()
x = Range("A2").CurrentRegion.Address
For Each c In Range(x)
If c = "VET" Then
MsgBox "Cell " & c.Address & " Contains VET."
End If
Next
End Sub
 

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