Fonctions VBAExcel
Les fonctions Excel en VBA
Sub proc_Somme_Normale_Et_Relative()
' Somme traditionnelle
Cells(1, 1).Formula = "=SUM(B2:B10)"
' Somme relative
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C:R[-10]C)"
' Somme à partir d'une variable
Dim maligne As Integer 'déclaration
maligne = 7 ' initialisation
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C:R[-" & maligne & "]C)"
End Sub
' Somme traditionnelle
Cells(1, 1).Formula = "=SUM(B2:B10)"
' Somme relative
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C:R[-10]C)"
' Somme à partir d'une variable
Dim maligne As Integer 'déclaration
maligne = 7 ' initialisation
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C:R[-" & maligne & "]C)"
End Sub
Sub proc_Recherche()
' Exemple classique :
Range("Z1").Value = "=VLOOKUP(Y1,A2:B5,2,0)"
' Exemple d'utilisation de rechercheV avec un texte "en dur" :
Range("Z1").Value = "=VLOOKUP(""Bienvenue"",A2:B5,2,0)"
' Recherche d'un itèm stocké dans une variable :
Exemple réalisé le 24 février 2011 en collaboration avec Séverine de l'ANFA
Dim str_mavariable As String ' Déclaration de variable
str_mavariable = "Bienvenue" ' Initialisation de la variable
Range("Z1").Value = "=VLOOKUP(""" & str_mavariable & """,A2:B5,2,0)"
End Sub
' Exemple classique :
Range("Z1").Value = "=VLOOKUP(Y1,A2:B5,2,0)"
' Exemple d'utilisation de rechercheV avec un texte "en dur" :
Range("Z1").Value = "=VLOOKUP(""Bienvenue"",A2:B5,2,0)"
' Recherche d'un itèm stocké dans une variable :
Exemple réalisé le 24 février 2011 en collaboration avec Séverine de l'ANFA
Dim str_mavariable As String ' Déclaration de variable
str_mavariable = "Bienvenue" ' Initialisation de la variable
Range("Z1").Value = "=VLOOKUP(""" & str_mavariable & """,A2:B5,2,0)"
End Sub


