Excel VBA: Determine if range is horizontal or vertical
excel, vba
Solution
How about this:
Function RangeIsVertical(rng As Range) As Boolean
RangeIsVertical = IIf(rng.Columns.Count = 1, 1, 0)
End Function
Sub Test()
Debug.Print RangeIsVertical(Range("A1")) //True
Debug.Print RangeIsVertical(Range("A1:A10")) //True
Debug.Print RangeIsVertical(Range("A1:B2")) //False
End Sub
Problem
I want to create a function that, among others, has a range as input. This range will be 1 row by ? columns or 1 columns by ? rows. In other words, it will be "one dimensional" - either horizontal or vertical. Based on whether it is H or V, certain calculations will be made. How can I determine if the range that is passed is horizontal or vertical?