Sélection en VBA
Résolu
CHARLYJACK
Messages postés
345
Date d'inscription
Statut
Membre
Dernière intervention
-
CHARLYJACK Messages postés 345 Date d'inscription Statut Membre Dernière intervention -
CHARLYJACK Messages postés 345 Date d'inscription Statut Membre Dernière intervention -
2 réponses
Bonjour,
Non testé ! :
Info
Non testé ! :
Option Explicit Sub CalculSum() Dim Result As Long, Total As Variant Application.ScreenUpdating = False For Each feuille In ActiveWorkbook.Sheets feuille.Activate tot = [D2] Result = Result + tot ' ->>>>> Définir la sélection Range("A2:C5").Select ' Ajout appel de fonction Total = SommeCouleurRougeText(Selection) Range("G12").Value = Total Total = NombredeCellRouge(Selection) MsgBox "Il y a " & Total & " Cellules rouges" Range("A1").Value = Total Next MsgBox Result End Sub ' 'Fait la somme des chiffres écrits en rouge de la sélection Function SommeCouleurRougeText(ByVal Cible As Range) As Variant Dim Cellule As Range Dim Total As Variant For Each Cellule In Cible '3 rouge et 1 pour le noir If Cellule.Font.ColorIndex = 3 Then If IsNumeric(Cellule) Then Total = Total + Cellule.Value End If Next SommeCouleurRougeText = Total End Function ' 'Compte le nombre de cellules colorées en rouge de la sélection Function NombredeCellRouge(ByVal Cible As Range) As Variant Dim Cellule As Range Dim Total As Variant For Each Cellule In Cible If Cellule.Interior.ColorIndex = 3 Then 'rouge Total = Total + Cellule.Count End If Next NombredeCellRouge = Total End Function '
Info