Convert column letter to number?

F

Frank Marousek

I'm writing a Sub that accepts a column letter as input in a UserForm. I
would like to convert this column letter to a column number for use in my
code. How is this done?
 
C

Charles Chickering

Why can't you use the letter?
strInput = Inputbox("Letter")
Range(strInput & 1).Select
Cells(1, strInput).Select

otherwise, if the activesheet is a worksheet then use this:
ColumnNumber = Range(strInput & 1).Column
 
P

paul.robinson

Hi
This sub will return 36

Public Sub tester()
Dim Letter As String
Letter = "AJ"
MsgBox Columns(Letter & ":" & Letter).Column
End Sub

Replace letter with your UserForm input.
regards
Paul
 
F

Frank Marousek

Why can't you use the letter?

Using the letter works fine. It was a rookie mistake. I was getting a "Type
mismatch" error which I thought was being caused because I was feeding a
string into where an integer was expected, but it turns out that error was
being caused by something else.

Thank you!
 

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

Top