Solved

Column Letter to a Column Number

Posted on 2013-06-28
2
299 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 500 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now