?
Solved

Column Letter to a Column Number

Posted on 2013-06-28
2
Medium Priority
?
346 Views
Last Modified: 2013-06-28
vba...

Is this code correct?

If i pass "A" = strLet

It comes back as "1" should it not be "0"



Public Function ColumnLetterToNumber(strLet As String)

Dim InputLetter As String
Dim OutputNumber As Integer
Dim Leng As Integer
Dim i As Integer

'InputLetter = InputBox("The Converting letter?")  ' Input the Column Letter

Leng = Len(strLet)
OutputNumber = 0


For i = 1 To Leng
   OutputNumber = (Asc(UCase(Mid(strLet, i, 1))) - 64) + OutputNumber * 26
Next i

'MsgBox OutputNumber   'Output the corresponding number
LtoN = OutputNumber


End Function


Freakin out on columns...
Columns start with  zero  ?





Thanks
fordraiders
0
Comment
Question by:Fordraiders
2 Comments
 
LVL 13

Accepted Solution

by:
Shanan212 earned 2000 total points
ID: 39284731
OutputNumber = Columns(strLet).Column

Open in new window


Try that instead of loop. You don't even need a function as this one liner can be used in other source procedures
0
 
LVL 3

Author Closing Comment

by:Fordraiders
ID: 39285488
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question