Home » excel » vba – how to find number of element present in array in google-script (marco excel)

vba – how to find number of element present in array in google-script (marco excel)

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an array,

    a="12-13-14" or "12-13"
    arr = Split(a, "-")
    b=Len(a)

it shows error. All I Need is b=3 or 2.

How to&Answers:

What you need is the find the upper limit of an array. To find the upper limit, use Ubound and to find the lower limit you can use LBound

Example

Sub Sample()
    Dim Arr(10)

    Debug.Print UBound(Arr) '~~> Returns 10.
    Debug.Print LBound(Arr) '~~> Returns 0.
End Sub

You can read more about it in UBound and LBound

So what you want is b=Ubound(arr)