TOP
Fonction VBA : UBound
Description
La fonction VBA UBound renvoie le plus grand index disponible pour le tableau spécifié.
Syntaxe UBound
UBound(tableau)
Ou
UBound(tableau, dimension)
Exemple VBA UBound
Utiliser la fonction UBound pour obtenir l'index de chacune des 2 dimensions du tableau :
- Sub UBoundExample1()
-
- Dim array(10, 4)
-
-
- MsgBox UBound(array)
-
-
- MsgBox UBound(array, 2)
-
- End Sub
Sub UBoundExample1()
Dim array(10, 4)
'L'indice maximum de la première dimension
MsgBox UBound(array) 'Retours: 10
'L'indice maximum de la deuxième dimension
MsgBox UBound(array, 2) 'Retours: 4
End Sub
Utilisation de la fonction UBound pour obtenir le nombre de valeurs dans le tableau créé par la fonction SPLIT :
- Sub UBoundExample2()
-
- link = "www.moonexcel.com.ua"
-
-
- array = Split(link, ".")
-
-
- number = UBound(array) + 1
-
-
- MsgBox number
-
- End Sub
Sub UBoundExample2()
link = "www.moonexcel.com.ua"
'Diviser une chaîne de caractères en un tableau
array = Split(link, ".")
'Nombre d'éléments du tableau (sachant que le tableau commence à 0)
number = UBound(array) + 1
'Afficher le nombre d'éléments du tableau
MsgBox number 'Retours: 4
End Sub