Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Range selection with variable (excel97+)

    I must be stupid!!
    I have the folllowing in Column A
    1
    2
    3
    4
    5
    In my code I have
    Dim lrows as long
    lrows = Worksheets("Sheet1").Range("A65536").End(xlUp).Row

    Now the problem
    I want to select cells 1 to 5 in column 1
    Range ("a1:a5"). Select ---works fine
    but
    Range ("a1:a(lrows)").Select ????----does not work ---can someone give me the correct format
    Sorry for stupid question but its bugging me
    PS --A Watch on value "lrows" gives a correct value of 5!!

  2. #2
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Range selection with variable (excel97+)

    The correct line should be:

    Range("a1:a" & (lrows)).Select

    if that's not immediately apparent, run the following:

    Sub test()

    Dim lrows As Double
    lrows = Worksheets("Sheet1").Range("A65536").End(xlUp).Row

    MsgBox lrows
    MsgBox "a1:a(lrows)"
    MsgBox "a1:a" & lrows

    Range("a1:a" & (lrows)).Select

    End Sub


    HTH

  3. #3
    2 Star Lounger
    Join Date
    Dec 2001
    Posts
    174
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Range selection with variable (excel97+)

    Thanx -its so simple when u know how to do it!!!!! but until u Know!!!
    Thanx

Posting Permissions

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