Fonction VBA : arrayEmpty
La fonction VBA arrayEmpty renvoie True si le tableau (array) est vide ou False si ce n'est pas le cas.
Si le tableau contient des valeurs "" ou des 0, il n'est pas considéré comme vide par la fonction.
Utilisation :
arrayEmpty(tableau)
Exemple de cas et valeurs renvoyées
Exemples simples avec Array() et différentes valeurs :
Sub exemple1()
tableau = Array()
MsgBox arrayEmpty(tableau) 'Renvoie TRUE
tableau = Array(Empty)
MsgBox arrayEmpty(tableau) 'Renvoie TRUE
tableau = Array(0)
MsgBox arrayEmpty(tableau) 'Renvoie FALSE
tableau = Array(1)
MsgBox arrayEmpty(tableau) 'Renvoie FALSE
tableau = Array("")
MsgBox arrayEmpty(tableau) 'Renvoie FALSE
tableau = Array("XLP", 4, "exemple")
MsgBox arrayEmpty(tableau) 'Renvoie FALSE
End Sub
Exemples avec des tableaux de taille fixe :
Sub exemple2()
'Exemple : tableau vide
Dim tableau1(10)
MsgBox arrayEmpty(tableau1) 'Renvoie TRUE
'Exemple : tableau non vide
Dim tableau2(10)
tableau2(2) = 0
MsgBox arrayEmpty(tableau2) 'Renvoie FALSE
'Exemple : tableau vidé
Erase tableau2 'Suppression du contenu
MsgBox arrayEmpty(tableau2) 'Renvoie TRUE
'Exemple : tableau vide (tableau3(2) vaut Empty à la fin)
Dim tableau3(10)
tableau3(2) = 1
tableau3(2) = Empty
MsgBox arrayEmpty(tableau3) 'Renvoie TRUE
End Sub
Exemples avec des tableaux dynamiques :
Sub exemple3()
'Exemple : tableau vide
Dim tableau1()
ReDim tableau1(10)
MsgBox arrayEmpty(tableau1) 'Renvoie TRUE
'Exemple : tableau non vide
Dim tableau2()
ReDim tableau2(10)
tableau2(2) = 0
MsgBox arrayEmpty(tableau2) 'Renvoie FALSE
'Exemple : tableau vidé
Erase tableau2 'Suppression du tableau
MsgBox arrayEmpty(tableau2) 'Renvoie TRUE
'Exemple : tableau redimensionné
ReDim tableau2(100)
MsgBox arrayEmpty(tableau2) 'Renvoie TRUE
'Exemple : tableau vide (tableau3(2) vaut Empty à la fin)
Dim tableau3()
ReDim tableau3(10)
tableau3(2) = 1
tableau3(2) = Empty
MsgBox arrayEmpty(tableau3) 'Renvoie TRUE
End Sub
Cette fonction est prévue pour les tableaux à 1 dimension uniquement.
Remarque : cette fonction nécessite l'installation du pack de fonctions XLP (un add-in gratuit pour Excel qui ajoute 92 nouvelles fonctions).