ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   To return the column number of a string (https://www.excelbanter.com/excel-worksheet-functions/148384-return-column-number-string.html)

[email protected]

To return the column number of a string
 
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.


Billy Liddel

To return the column number of a string
 
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
" wrote:

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.



Billy Liddel

To return the column number of a string
 
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


"Billy Liddel" wrote:

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
" wrote:

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.




All times are GMT +1. The time now is 04:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com