Why R/T 438?

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
Rich (BB code):
Sub Foo()
Dim MyRow As Integer, MyColNum As Integer
Dim MyColLtr As String
MyValue = InputBox("Enter text value")
    For Each C In Range("Rng")
        If C.Row > 1 And C.Column > 1 Then
            If MyValue = C Then
                MyRow = C.Row
                MyColNum = C.Column
                MyColLtr = Application.WorksheetFunction.Address(MyRow, MyColNum, 4)
            ActiveCell.Value = "Row " & MyRow & " and Column " & MyColLtr
            Exit Sub
            End If
        End If
    Next C
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
You can't use the worksheet function ADDRESS with Application.WorksheetFunction.
 
Upvote 0
You can't use the worksheet function ADDRESS with Application.WorksheetFunction.

I just LOVE how Excel "sometimes" works, or doesn't work.. grrrrr:rolleyes:
Thanks for pointing out this exception. Can you suggest a workaround?
 
Upvote 0
Somewhat inelegant but maybe (untested)

Code:
Sub Foo()
Dim MyRow As Integer, MyColNum As Integer
Dim MyColLtr As String
MyValue = InputBox("Enter text value")
    For Each C In Range("Rng")
        If C.Row > 1 And C.Column > 1 Then
            If MyValue = C Then
                MyRow = C.Row
                MyColNum = C.Column
                MyColLtr = Cells(MyRow, MyColNum).Address(False, False)
                MyColLtr = Left(MyColLtr, InStr(MyColLtr, ":") - 1)
            ActiveCell.Value = "Row " & MyRow & " and Column " & MyColLtr
            Exit Sub
            End If
        End If
    Next C
End Sub
 
Upvote 0
MyColLtr = Split(Cells(1, MyColNum).Address, "$")(1)

or
MyColLtr = Split(c.Address, "$")(1)
 
Last edited:
Upvote 0
Or alternately....

MyColLtr = Split(Columns(MyColNum).Address(, 0), ":")(0)
 
Upvote 0
It's times like this when being a part of such a professional "community" comes home!!!
Thanks to each of you for your input - I rarely go to Thread Tools - Show Printable Version, but your inputs are so good I was compelled - to further study each (off-line).

Googling - I also came across this one-liner, which also works...

Again thanks,,

Jim

Code:
MyColLtr = Left(Cells(MyRow, MyColNum).Address(1, 0), InStr(1, Cells(MyRow, MyColNum).Address(1, 0), "$") - 1)
 
Upvote 0
@Jim May,

There are lots of ways to achieve this using String manipulations. Here is another one using an InStr method similar to what you posted...

MyColLtr = Left(Columns(MyColNum).Address(, 0), InStr(Columns(MyColNum).Address(, 0), ":") - 1)

Note I used Columns rather than Cells so that there is no need to specify a Row number that will never be used in the evaluation.
 
Upvote 0
Suggest this...

Option Explicit

Sub x()
Dim MyRow, MyColNum
MyRow = 5
MyColNum = 7
MsgBox Cells(MyRow, MyColNum).Address(0, 0)

End Sub
 
Upvote 0
VoG:

MyColLtr = Cells(MyRow, MyColNum).Address(False, False) ' produces H14 (without the ":")

Jim
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top