PDA

View Full Version : Sleeper: Range



-07-
04-06-2005, 04:33 AM
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-

Steiner
04-06-2005, 05:12 AM
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?

-07-
04-06-2005, 05:27 AM
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

Zack Barresse
04-06-2005, 08:38 AM
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 :2p: