Consulting

Results 1 to 7 of 7

Thread: Solved: Syntax question: Range(....)

  1. #1

    Solved: Syntax question: Range(....)

    In the first two lines of code, this is confusing me why the first one is accepted/valid by the compiler rather than the second one.
    The third "&" is required to create the proper range stmt. for the compiler, why?

    [VBA]
    Range("J" & i & ":O" & i).Delete shift:=xlShiftUp
    Range("J" & i ":O" & i).Delete shift:=xlShiftUp
    [/VBA]

    [VBA]
    For i = lrwSource To 3 Step -1
    If Cells(i, "O").Value = "x" Then
    Range("J" & i & ":O" & i).Delete shift:=xlShiftUp
    End If
    Next i
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Doug

    It just is.

    Why do you think it wouldn't be needed?

    You are concatenating "J" and(&) i and(&) ":O" and(&) i.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    When concatenating, every item has to be acted upon, they don't do it implicitly.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Thanks Bob.

    Norie to answer your ?
    When reading it literally- it would be:

    [VBA]Range("J3 & : O3").cells.delete[/VBA]

    which if this were even possible is saying these two cells,
    not the range of

    [VBA]
    Range("J3:O3").cells.delete
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Range("J3,O3").cells.delete
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Quote Originally Posted by YellowLabPro
    Thanks Bob.

    Norie to answer your ?
    When reading it literally- it would be:

    [vba]Range("J3 & : O3").cells.delete[/vba]
    Eh, no it wouldn't.

    For just two cells it would be this.
    [vba]
    Range("J3, O3").Delete[/vba]

    PS You don't need Cells here.

  7. #7
    Bob,
    Had not thought about it like that, that is cool. What I was trying to convey was the idea of being literal, the " & : " would not be written / read that way.
    But I get what you meant in the first post regarding concatenating and I see your point here of a range being separated by the comma providing two valid ranges....
    Thanks.... keeping me on my toes
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

Posting Permissions

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