Range() using two variables.

  • I know how to use the range with a variable. Like:

    Code
    1. Activesheet.Range("D26:F" & x)


    However, at times i need to pass x into both sections of the range, other times i might need to pass both x and y.
    Here are some examples (none of them work).


    Code
    1. ActiveSheet.Range("D:F" & x )
    2. ActiveSheet.Range("D:F" & x & y)
    3. ActiveSheet.Range("D" & x : "F" & x)



    Is there a way to do this correctly?

  • Re: Range() using two variables.


    Try:


    [VB]
    ActiveSheet.Range("D" & x, "F" & x)
    [/VB]

    You can say "THANK YOU" for help received by clicking the :thumbup: icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Re: Range() using two variables.


    Or


    Code
    1. ActiveSheet.Range("D" & x & ":F" & y)


    variables x and y must be properly declared and defined as long type


    The correct construction is


    Range("Column Letter" & variable & ":Column letter" & variable)