+ Reply to Thread
Results 1 to 11 of 11

how to extract column letter of a cell & select cell by referencing its column number

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Smile how to extract column letter of a cell & select cell by referencing its column number

    If I have a named cell in the worksheet, "myCell", how can I extract it's column letter using VB?

    Also, in addition to the above, if I have a column number (not letter) and a row number of a cell, how can I use that info to select that cell in my worksheet? So for example, I want to be able to select cell C5, (and all my sub knows is the cell's row, which is 5, and column number which is 3).

    Thank you.
    Last edited by luv2glyd; 07-12-2010 at 08:58 AM.
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Hi luv2glyd
    use "Range("myCell").Column"
    Please Login or Register  to view this content.
    Cells( Row number, column Number)

    a1 is cells (1,1)
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Thank you Pike. That answers my second quesiton. On occasion, I need to use actual column letter in my code vs. column number (for example: letter of cell ADB4 is "ADB"). How can I extract that info?

    Thank you

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Hi luv2glyd

    what are you trying to do?
    you can use
    cells(4,"ADB")

    but where is ADB4 comming from?

  5. #5
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    I can use column numbers most of the time, but someitmes when i work with a lot of data (which spans way to the right in the worksheet), it'd be nice to use column letters, so when I look at the code and the data location in workbook, its easier to check the code and the location of data for consistency, to make sure everything is alligned and working correctly. So rather then figuring out what the column number of a cell is (in example below column number of cell DK is 115), it'd be nice to reference that cell by column letter. Here's just one of the examples of the code I have:

    Please Login or Register  to view this content.
    So for the example above, I'd like to be able to use data_start_column in place of "DK" and extract this column letter in a way similar to:

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Also, many times the way I write code, for simplicity sake, is by recording a macro, and then going in and modifying it to do what I need it to do. Excel records everything with references to column letters vs. column numbers, so when I go in to tweak something, it'd be nice to know how to get the column letter, and then just insert it in the macro

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Try these functions
    Please Login or Register  to view this content.
    Call in VBa
    Please Login or Register  to view this content.
    Or as a UDF in Excel
    =ColumnLetter(A1)

    Please Login or Register  to view this content.
    Call in VBa
    Please Login or Register  to view this content.

    Hope this helps
    Last edited by Marcol; 07-11-2010 at 01:34 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Use Excel's built-in facilities:

    Please Login or Register  to view this content.

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    And if you want to complete the set....
    Please Login or Register  to view this content.
    Enter in Excel as
    =ColumnName(A1)

  11. #11
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: how to extract column letter of a cell & select cell by referencing its column nu

    Great! Thank you every one. I think I like the last two solutions the best - short and sweet to get what I need. Sorry for the late reply - was gone yesterday.
    Last edited by luv2glyd; 07-12-2010 at 08:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1