Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting Two Different Ranges (XP; SR3)

    How would one go about passing a variable range to the following code: Range A23 never changes but A66 does.

    Sub Select_Two_Ranges()
    Range("A23,A66").Select
    End Sub


    The code needs to pass cells referencing rows 6, 7, 8, 9 and 10 into the formula Range("A23,A?[img]/forums/images/smilies/biggrin.gif[/img]?").Select

    I tried declaring a variable as a range and setting the range but have had no luck.

    Any suggestions are appreciated,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Selecting Two Different Ranges (XP; SR3)

    Since the cell reference is a string, you can use concatenation to assemble it:

    Dim lngRow As Long
    lngRow = 6 ' or 7 etc.
    Range("A23,A" & lngRow & "" & lngRow).Select

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting Two Different Ranges (XP; SR3)

    Thanks Hans,

    I didn't see the string...too focused on ranges.

    John

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selecting Two Different Ranges (XP; SR3)

    I would suggest a slight difference to what Hans suggested.

    <pre>Sub Select_Two_Ranges(strRng as String)
    Range("A23," & strRng).Select
    End Sub
    </pre>


    Call it like this:

    <pre> Call Select_Two_Ranges("A66")
    </pre>

    Legare Coleman

Posting Permissions

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