Consulting

Results 1 to 4 of 4

Thread: Sleeper: Range

  1. #1

    Sleeper: Range

    Hi!

    Can U please explain me the effect of this
    Range("A:M,M3").Select
    Range("M3").Select is understood.....
    Columns("A:M").Select is also understood...
    but what is
    Range("A:M,M3").Select
    -07-

  2. #2
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    It should make no difference to Range("A:M") select, as this one already selects the whole columns A to M where M3 is a part of.

    If it was Range("A:L,M3") it would mean columns A to L plus cell M3. Maybe this is a result of removing some cells.

    Could you post some more context on that one?

  3. #3
    What I observed is....

    Range("B:M").Select...... Columns b to m are selected
    Range("B:M,M3").Select...... columns b to m are selected and cell B1 is set selected/active

    same when U say
    Range("D:K,K3").Select...... columns d to k are selected and cell D1 is set selected/active

    regards

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    The second Range was not Activated, it was Unioned. Basically, record a macro selecting at least 2 entire columns, then hold the Ctrl key and select a cell within the same selection. Now look at your macro. It would look the same, much like this ...

    Option Explicit
    
    Sub Macro1()
    'Macro1 Macro
    ' Macro recorded 4/6/2005 by Zack
    Range("B:D,B2").Select
        Range("B2").Activate
    End Sub
    Steiner is correct in that you don't need it. You don't even need to select any of it to work with it - not in VBA. The latter range is selected because it is the last cell unioned in the range because you used a select, and only because of this, otherwise you wouldn't see it selected (not if you were only working with the range).

    I have a feeling this is the result of a recorded macro that you are trying to understand. (I could very well be wrong.) Understanding recorded code is a great step and is an excellent learning tool. Don't forget it's equally as important to learn from good code as well. If you post your code, I'd be willing to bet that a much more efficient and cleaner looking code would result. This would be optimal for learning VBA.

    My

Posting Permissions

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