I am trying to return the number of columns in a range, sometimes I need one range, but sometimes I need more than one range.
I have included additional ranges to select multiple ranges. If I reference a range in a function prototype that I did not provide in the spreadsheet, I get #Value! error.
I need a way to check if additional ranges are null, empty, etc., so I don't need to reference the range.
This is a prototype of a VBA function: -
Function GetColoumnCount(ARange1 As Range, Optional ARange2 As Range, Optional ARange3 As Range, Optional ARange4 As Range) As Integer Dim Result As Integer Result = 0 Result = ARange1.Columns.Count ' This works Result = ARange1.Columns.Count + ARange2.Columns.Count ' This doesn't work GetColoumnCount = Result End Function
In my table, I have to enter this in the cell for the function to work.
=GetColoumnCount(BC34:BK34, BC35:BD35, BE35:BF35, BG35:BH35)
this violates the purpose of the optional arguments.
source share