Use the UBound and LBound functions for print size of an Array in Excel VBA ?

  Excel Interview Q&A

Today we will read how to get the size of an array in Excel VBA, you can use the UBound and LBound functions.

create a excel data file like below snapshot or download the excel demo file

Place a command button on your worksheet and add the following code lines:

Option Explicit

Private Sub CommandButton1_Click()

Dim Films(1 To 5, 1 To 2) As String, x As Integer, y As Integer

x = UBound(Films, 1) - LBound(Films, 1) + 1
y = UBound(Films, 2) - LBound(Films, 2) + 1

MsgBox "This array consists of " & x * y & " elements"

End Sub
Use the UBound and LBound functions for print size of an Array in Excel VBA ?

Use the UBound and LBound functions for print size of an Array in Excel VBA ?

LEAVE A COMMENT