borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Help me.....it\'s urgent)Next Topic (Find in txt file to txt1.text) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : converting Column number to letters Solved Topic
Poster Message
neutrall
Level: Master


Registered: 28-03-2004
Posts: 122

icon converting Column number to letters

Hi to all,
  Anyone can suggest me a way to easilly find out the column letter by using the number...

EX : Column number 5 is actually equal to "E".

So far, I went the long way around :

Dim ExlLetter(5) as string

  ExlLetter(1) = "A"
  ExlLetter(2) = "B"
  ExlLetter(3) = "C"
  ExlLetter(4) = "D"
  ExlLetter(5) = "E"

  ColumnLetter = ExlLetter(ColumnNumber)



Maybe there already a function that does so. Since my VBA code actually to be able to goo all the way to the last column (IV) and that a huge array to build manually!

thank You!



____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.

07-10-2005 at 01:05 PM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: converting Column number to letters

Hi,
why do you need the letter? Excel supports number ranges too.
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

07-10-2005 at 02:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
neutrall
Level: Master


Registered: 28-03-2004
Posts: 122
icon Re: converting Column number to letters

That's interesting...

  Well, I wanted number to letter since I didn't know that excel supported numbered range.

  Does it work the same as a lettered range?

EX : Range("A1:b2")   = Range("11:22")  ?


since i am using it for a range (With a graph).

Thank You!

____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.

07-10-2005 at 03:02 PM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: converting Column number to letters

Hi,
I've written a little function to calculate the letters from a given number, in case you really need it:

Public Function GetColumnLetters(ByVal intNumber As Integer) As String
    Dim strRet As String
    
    Dim d As Integer
    
    
    strRet = ""
    If intNumber <= 26 Then
        strRet = Chr(intNumber + Asc("A") - 1)
    Else
        
        Do
            d = intNumber \ 26
            
            strRet = strRet & Chr(d + Asc("A") - 1)
            
            
    
            intNumber = intNumber - (d * 26)
            
        Loop While intNumber > 26
        strRet = strRet & Chr(intNumber + Asc("A") - 1)
    End If
    GetColumnLetters = strRet
End Function


Hope this helps,
Kieron

[Edited by stickleprojects on 07-10-2005 at 03:57 PM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

07-10-2005 at 03:56 PM
View Profile Send Email to User Show All Posts | Quote Reply
neutrall
Level: Master


Registered: 28-03-2004
Posts: 122
icon Re: converting Column number to letters

It's work extremelly wells!!!
Thank You!


____________________________
A Stick give a wise man something to think about... and a fool, something to put in is mouth.

13-10-2005 at 08:13 PM
View Profile Send Email to User Show All Posts Visit Homepage ICQ | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : converting Column number to letters Solved Topic
Previous Topic (Help me.....it\'s urgent)Next Topic (Find in txt file to txt1.text) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder