Excel - convert letters to numbers

Asked By JT on 03-Jun-10 12:21 PM
How do I convert letters to numbers with VBA.  On one of the sheets in my
macro there is a date field.  The user indicates the date field by entering
1 or 2 or 4 and it is not a problem.  However, some users enter letters and I
need to convert those letters to the appropriate number, so I know which
column contains dates.

Thanks for the help.

--
JT




GS replied to JT on 03-Jun-10 12:31 PM
JT wrote on 6/3/2010 :

If the letters represent the column label:
DateColumn = Columns("F")

where "A" is column 1, "B" is column 2, and so on.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Jim Cone replied to JT on 03-Jun-10 12:34 PM
' Jun 08, 2002 - Created - Jim Cone
' Returns the number of the column from the provided column letters.
' The string argument is passed ByVal so a variant can be used.
'==================================================
Function GetColumnNumber(ByVal ColLetters As String) As Long
On Error GoTo BadColumn
GetColumnNumber = Columns(ColLetters).Column
Exit Function
BadColumn:
Beep
GetColumnNumber = 0
End Function
--
Jim Cone
Portland, Oregon  USA
http://www.mediafire.com/PrimitiveSoftware





How do I convert letters to numbers with VBA.  On one of the sheets in my
macro there is a date field.  The user indicates the date field by entering
1 or 2 or 4 and it is not a problem.  However, some users enter letters and I
need to convert those letters to the appropriate number, so I know which
column contains dates.
Thanks for the help.
--
JT
Gary''s Student replied to JT on 03-Jun-10 01:00 PM
How about:

Sub dural()
Dim s As String
s = Application.InputBox(prompt:="enter a column letter:", Type:=2)
S2 = s & ":" & s
n = Range(S2).Column
MsgBox (n)
End Sub
--
Gary''s Student - gsnu201003