PC Review


Reply
Thread Tools Rate Thread

Convert Column letter designation to a number

 
 
Fred Holmes
Guest
Posts: n/a
 
      15th Mar 2007
Is there a code statement that will convert the letter designation of
a column to a number, e.g., convert "A" to "1" and and so forth using
the letter pattern used to designate columns in a worksheed?

"AA" would be converted to "27".

I need to do arithmetic using the column numbers.

Thanks,

Fred Holmes
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      15th Mar 2007
http://www.vba-programmer.com/Snippe...tr_To_Num.html


"Fred Holmes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a code statement that will convert the letter designation of
> a column to a number, e.g., convert "A" to "1" and and so forth using
> the letter pattern used to designate columns in a worksheed?
>
> "AA" would be converted to "27".
>
> I need to do arithmetic using the column numbers.
>
> Thanks,
>
> Fred Holmes



 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      15th Mar 2007
Give this a whirl...

Sub test()
MsgBox LetterToNumber("A")
MsgBox LetterToNumber("r")
MsgBox LetterToNumber("FA")
End Sub

Public Function LetterToNumber(ByVal Letter As String) As Long
Dim lngLength As Long
Dim lng As Long
Dim lngReturn As Long

lngLength = Len(Letter)
For lng = 1 To lngLength
lngReturn = lngReturn + (Asc(UCase(Mid(Letter, lng, 1))) - 64) _
* ((lngLength - lng) * 25 + 1)
Next lng
LetterToNumber = lngReturn
End Function
--
HTH...

Jim Thomlinson


"Fred Holmes" wrote:

> Is there a code statement that will convert the letter designation of
> a column to a number, e.g., convert "A" to "1" and and so forth using
> the letter pattern used to designate columns in a worksheed?
>
> "AA" would be converted to "27".
>
> I need to do arithmetic using the column numbers.
>
> Thanks,
>
> Fred Holmes
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Mar 2007
You can get the column number by:

msgbox cells(1,"AA").column
or
msgbox range("AA"&1).column

If you have a couple of range variables, you could use:

dim myCell_1 as range
dim myCell_2 as range

'set them to something

msgbox mycell_2.column - mycell_1.column
(to see the difference)

Fred Holmes wrote:
>
> Is there a code statement that will convert the letter designation of
> a column to a number, e.g., convert "A" to "1" and and so forth using
> the letter pattern used to designate columns in a worksheed?
>
> "AA" would be converted to "27".
>
> I need to do arithmetic using the column numbers.
>
> Thanks,
>
> Fred Holmes


--

Dave Peterson
 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      15th Mar 2007
Function GetColNum(myColumn As String) As Integer
GetColNum = Columns(myColumn & ":" & myColumn).Column
End Function

=getcolnum("AA") - getcolnum("M") returns 14


Gord Dibben MS Excel MVP

On Thu, 15 Mar 2007 18:32:25 -0500, Dave Peterson <(E-Mail Removed)>
wrote:

>You can get the column number by:
>
>msgbox cells(1,"AA").column
>or
>msgbox range("AA"&1).column
>
>If you have a couple of range variables, you could use:
>
>dim myCell_1 as range
>dim myCell_2 as range
>
>'set them to something
>
>msgbox mycell_2.column - mycell_1.column
>(to see the difference)
>
>Fred Holmes wrote:
>>
>> Is there a code statement that will convert the letter designation of
>> a column to a number, e.g., convert "A" to "1" and and so forth using
>> the letter pattern used to designate columns in a worksheed?
>>
>> "AA" would be converted to "27".
>>
>> I need to do arithmetic using the column numbers.
>>
>> Thanks,
>>
>> Fred Holmes


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Mar 2007
This
msgbox range("AA"&1).column

should be
msgbox range("AA1").column
or
msgbox range("AA" & "1").column


Dave Peterson wrote:
>
> You can get the column number by:
>
> msgbox cells(1,"AA").column
> or
> msgbox range("AA"&1).column
>
> If you have a couple of range variables, you could use:
>
> dim myCell_1 as range
> dim myCell_2 as range
>
> 'set them to something
>
> msgbox mycell_2.column - mycell_1.column
> (to see the difference)
>
> Fred Holmes wrote:
> >
> > Is there a code statement that will convert the letter designation of
> > a column to a number, e.g., convert "A" to "1" and and so forth using
> > the letter pattern used to designate columns in a worksheed?
> >
> > "AA" would be converted to "27".
> >
> > I need to do arithmetic using the column numbers.
> >
> > Thanks,
> >
> > Fred Holmes

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      16th Mar 2007
why not just:

columns("AA").column

--


Gary


"Fred Holmes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a code statement that will convert the letter designation of
> a column to a number, e.g., convert "A" to "1" and and so forth using
> the letter pattern used to designate columns in a worksheed?
>
> "AA" would be converted to "27".
>
> I need to do arithmetic using the column numbers.
>
> Thanks,
>
> Fred Holmes



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert column letter to number? Frank Marousek Microsoft Excel Programming 4 19th Oct 2006 05:10 PM
convert column number to letter lvcha.gouqizi Microsoft Excel Programming 16 31st Oct 2005 03:39 PM
Convert Column letter to number =?Utf-8?B?c2x5bWVhdA==?= Microsoft Excel Programming 5 27th Oct 2005 07:13 PM
Re: Example: how to convert a column letter to a number Ron de Bruin Microsoft Excel Programming 1 16th Sep 2004 05:01 PM
convert column number to letter(s) =?Utf-8?B?U2NvdHQ=?= Microsoft Excel Worksheet Functions 1 13th Nov 2003 04:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:41 AM.