VBA UBound & LBound -funktioner

UBound Beskrivning

Returnerar det högsta abonnemanget för en dimension av en array.

Enkla UBound -exempel

1234 Sub UBound_Example ()Dim a (3 till 10) som heltalMsgBox UBound (a)Avsluta Sub

Resultat: 10

UBound Syntax

1 UBound (ArrayName, [Dimension])

UBound -funktionen innehåller 2 argument:

ArrayName: Array -variabelns namn.

Dimensionera: [Valfritt] Heltal som anger vilken dimensions nedre gräns som returneras. Använd 1 för den första dimensionen, 2 för den andra, etc. 1 om den tillåts.

Exempel på Excel VBA UBound -funktion

1234567 Sub UBound_Example1 ()Dim arrVärde (1 till 5, 4 till 8, 12 till 25)MsgBox UBound (arrValue)MsgBox UBound (arrValue, 1)MsgBox UBound (arrValue, 2)MsgBox UBound (arrValue, 3)Avsluta Sub

Resultat: 5, 5, 8, 25

LBound Beskrivning

Returnerar det lägsta abonnemanget för en dimension av en array.

Enkla LBound -exempel

1234 Sub LBound_Example ()Dim a (3 till 10) som heltalMsgBox LBound (a)Avsluta Sub

Resultat: 3

LBound Syntax

1 LBund(ArrayName, [Dimension])

LBound -funktionen innehåller 2 argument:

ArrayName: Array -variabelns namn.

Dimensionera: [Valfritt] Heltal som anger vilken dimensions nedre gräns som returneras. Använd 1 för den första dimensionen, 2 för den andra, etc. 1 om den tillåts.

Exempel på Excel VBA LBound -funktion

1234567 Sub LBound_Example1 ()Dim arrVärde (1 till 5, 4 till 8, 12 till 25)MsgBox LBound (arrValue)MsgBox LBound (arrValue, 1)MsgBox LBound (arrValue, 2)MsgBox LBound (arrValue, 3)Avsluta Sub

Resultat: 1, 1, 4, 12

wave wave wave wave wave