Solved

Column Letter to a Column Number

Posted on 2013-06-28
2
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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