Skip to main content

VBA for Excel

Below are some useful functions to take with you and accelerate your development!

    Public Function NumRows(ByRef var As Variant) As Integer
    
    Select Case DimensionCount(var)
        Case 0
            NumRows = 1
        Case 1
            NumRows = UBound(var) - LBound(var) + 1
        Case Else
            NumRows = UBound(var, 1) - LBound(var, 1) + 1
    End Select
    
End Function
    Public Function NumCols(ByRef var As Variant) As Integer
    Case DimensionCount(var)
        Case 0, 1
            NumCols = 1
        Case Else
            NumCols = UBound(var, 2) - LBound(var, 2) + 1
    End Select
    
End Function