+ Reply to Thread
Results 1 to 7 of 7

Select Range of cells when rows are known, current column is not.

  1. #1
    Registered User
    Join Date
    10-10-2003
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    88

    Select Range of cells when rows are known, current column is not.

    Lets say cell c12 is the active cell. How would one select Range("C2:C7") in VBA if one did not know the column letter, only the row numbers.


    Something like:

    Range(activecell.column + "2:" + activecell.column + "7").select

    I know that activecell.column for column C = 3 and the code above does not work (big surprise). I'm pretty sure there must be a simple, straightforward way to get the column letter out of the activecell.

    How would one reference the column?

    Thanks,

    BB
    Last edited by captbluefin; 12-20-2012 at 12:03 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Select Range of cells when rows are known, current column is not.

    Welcome to a can of worms.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-10-2003
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    88

    Re: Select Range of cells when rows are known, current column is not.

    Unfortunately, the column letter is unknown. We know which rows of cells need to be selected. It is the letter for the column that is unknown. If we knew which column letter to use, a simple select statement would suffice. The only unknown is the column letter.

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Select Range of cells when rows are known, current column is not.

    Quote Originally Posted by captbluefin View Post
    Unfortunately, the column letter is unknown. We know which rows of cells need to be selected. It is the letter for the column that is unknown. If we knew which column letter to use, a simple select statement would suffice. The only unknown is the column letter.
    If you were to use....
    Please Login or Register  to view this content.
    It would work, but only if the active cell were not on row10 or up.

    That is why I said, "welcome to a can of worms".

  5. #5
    Registered User
    Join Date
    10-10-2003
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    88

    Re: Select Range of cells when rows are known, current column is not.

    This worked:

    Please Login or Register  to view this content.
    Thanks for looking.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Select Range of cells when rows are known, current column is not.

    Or maybe something like this?

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Select Range of cells when rows are known, current column is not.

    captbluefin
    Looking at this again, would these simplified codes work?

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

+ 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