Results 1 to 8 of 8

Thread: [RESOLVED] Seleting specific range

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    Resolved [RESOLVED] Seleting specific range

    I am using Excel 2007.

    It seems so simple, but I can't piece together the last line of code. I'm drawing a blank for some reason.

    Code:
    'Stores the number of the last row
    Range("G1").Select
    Selection.End(xlDown).Select
    intLastRow = ActiveCell.Row
    
    'Stores the number of the last column
    Range("G1").Select
    Selection.End(xlToRight).Select
    intLastColumn = ActiveCell.Column
    What I'm trying to do is select the entire group range. I tried using...

    Range("G1", ????).select

    The problem here is if I use intLastColumn it'll give me the # of the column (Ex. A = 1, B = 2, C = 3, etc). I need the letter so I can put...

    "P" & intLastRow

    ...in orde to select the entire group. Is there a way to Convert the number back to the column letter or even store the Column letter rather than the #?

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Seleting specific range

    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    Re: Seleting specific range

    Are you sure it's in there?

    Let me add a little more depth before referring to the link again as I was unable to apply any of it to what I needed.

    The number of columns & rows changes every month. And, the first column and first row are the only ones that are always populated with data. The cells in the middle are sometimes blank. That is why I was targetting the initial G1 cell and doing the xlToRight & xlDown to store the last row/column.

    That's why when I stored the intLastColumn I was hoping I could convert it back to the column letter rather than the number or figure out how to store the Letter rather than the Number.

    If the answer is still in the link I'll look again, but at first look I didn't see anything I could use in this situation.


    Here's an example.....
    Attached Images Attached Images  

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Seleting specific range

    Do you want the range G1:L7 ?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    Re: Seleting specific range

    Yes, I do. But I have to keep in mind that the number of rows & columns can change every month. And, the cells in the middle don't always have data just as in the example.

    That's why in the example I provided I was storing the last row/column so I could trying to select the entire group by entering...

    Range("G1", ????).Select
    Last edited by lilmark; Oct 8th, 2009 at 03:00 PM.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Seleting specific range

    Ok will the first row and the first column have data always? if yes then this will help you...

    vb Code:
    1. Sub GetRangeAddress()
    2.     Range(Range("D7"), Range("D7").End(xlToRight)).Select
    3.     Range(Selection, Selection.End(xlDown)).Select
    4.     MsgBox Selection.Address
    5. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    367

    Re: Seleting specific range

    Figured how to select the entire group where the rows/columns aren't always constant...


    Code:
        Dim intLastRow As Integer
    
        Range("G1").Select
        Selection.End(xlDown).Select
        intLastRow = ActiveCell.Row
        Range("G1").Select
        Selection.End(xlToRight).Select
        Range("G1", ActiveCell.Offset(intLastRow - 1, 0)).Select
    Wish you could store the column letter rather than the number of columns.

  8. #8
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] Seleting specific range

    Figured how to select the entire group where the rows/columns aren't always constant...
    Not even the 1st row and 1st column?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width