Fonction VBA : isInt

La fonction VBA isInt renvoie True si la valeur est un nombre entier ou False si ce n'est pas le cas.

Utilisation :

isInt(valeur_a_tester)


Exemple d'utilisation

Vérification de la valeur dans une condition if isInt(valeur) :

Sub exemple()

    valeur = 57
    
    If isInt(valeur) Then
        MsgBox "C'est un nombre entier !"
    End If

End Sub
fonction vba excel is int

Quelques exemples de valeurs retournées par la fonction :

Sub exemple2()

    MsgBox isInt(5) 'Renvoie TRUE
    MsgBox isInt("5") 'Renvoie TRUE (depuis la version 2 de l'add-in)
    MsgBox isInt(-64) 'Renvoie TRUE
    MsgBox isInt(1.2) 'Renvoie FALSE
    MsgBox isInt("ABC") 'Renvoie FALSE
    MsgBox isInt(34.74128) 'Renvoie FALSE
    MsgBox isInt(8 / 4) 'Renvoie TRUE
    MsgBox isInt(8 / 5) 'Renvoie FALSE
    MsgBox isInt(5.65) 'Renvoie FALSE
    MsgBox isInt(Int(5.65)) 'Renvoie TRUE

End Sub

Remarque : cette fonction nécessite l'installation du pack de fonctions XLP (un add-in gratuit pour Excel qui ajoute 92 nouvelles fonctions).

Cette fonction est également disponible dans les astuces VBA.