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

    syntax pls (excel97+)

    Stuck on this one
    var=8
    range("a5:a" & var).select-----selects cells a5 to a8
    range("a8:k" & var).select----selects row 8 columns "a" to "k"
    The following doesn't work ---incorrect syntax ofcourse but how is it done?
    range("a & var:k" & var).select---need correct syntax please
    I tried all sorts of bracketing to no avail!!
    Regards
    Smbs

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

    Re: syntax pls (excel97+)

    Try this:

    <code>Range("A" & var & ":K" & var).Select</code>

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

    Re: syntax pls (excel97+)

    Try:

    <pre> Range("A" & var & ":K" & var).Select
    </pre>

    Legare Coleman

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

    Re: syntax pls (excel97+)

    Thanx all
    It's easy when u know how!!
    I wasted about an hour trying to figure it out myself before I gave up!!
    BTW can u explain the logic behind the syntax?
    Thanx once again
    Smbs

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

    Re: syntax pls (excel97+)

    <pre> Range("A" & var & ":K" & var).Select
    </pre>



    If var = 8, then what you want to end up with is the equivalent of:

    <pre> Range("A8:K8").select
    </pre>


    "A" & var give you the string A8. Adding & ":K" gives you A8:K. Adding & var on the end give you A8:K8 which is what you want.

    Your try:

    <pre> range("a & var:k" & var).select
    </pre>


    Takes the string "a & var:k" and concatenates the value of var to it resulting in the string "a & var:k8", which is not what you want. If you put the "& var" inside the quotes, they are just characters in the string.
    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
  •