PDA

View Full Version : If 2D range, do this...



alstubna
05-20-2011, 10:14 AM
Hello everyone!

Not much of a programmer.

How do I phrase this in VBA:

If the selected range is a 2 dimensional range
do this
else
do this


Thanks!

GTO
05-20-2011, 10:19 AM
hi there,

The selected range in Excel will always be two-dimensional as it applies to returning an array. Is that what you are trying to do, or just find out if more than one column and/or more than one row is selected?

Mark

p45cal
05-20-2011, 10:20 AM
With Selection
If .Columns.Count > 1 And .Rows.Count > 1 Then
MsgBox "it's a 2d range"
Else
MsgBox "it's not a 2d range"
End If
End With

alstubna
05-20-2011, 10:25 AM
hi there,

The selected range in Excel will always be two-dimensional as it applies to returning an array. Is that what you are trying to do, or just find out if more than one column and/or more than one row is selected?

Mark
Just find out if more than 1 column/row is selected.

I think I can use p45cal's suggestion.

Thanks!

alstubna
05-20-2011, 10:27 AM
With Selection
If .Columns.Count > 1 And .Rows.Count > 1 Then
MsgBox "it's a 2d range"
Else
MsgBox "it's not a 2d range"
End If
End With

Wow! That was quick.

I should be able to use that.

Thanks!