Microsoft 365 sommes automatiques par dates

nico833

XLDnaute Nouveau
Bonjour,

j'ai un fichier excel avec des dates dans la colonne A et des données en colonne C.
Pour la colonne A j'ai réussi à faire en sorte d'intégrer une ligne entre chaque date différentes grâce au code suivant que j'ai trouvé sur le forum.

Sub Essai()
Application.ScreenUpdating = False
Dim Ligne As Long
For Ligne = Range("A65536").End(xlUp).Row To 2 Step -1
If Range("A" & Ligne) <> Range("A" & Ligne - 1) Then
Range("A" & Ligne).EntireRow.Insert
End If
Next
Application.ScreenUpdating = False
End Sub

j'aimerai maintenant additionner les données de la colonne C en ayant un résultat par date (faire la somme par jour), je vous joins un screen de mon fichier en exemple.
Si en plus on peut faire que ça se note en surbrillance ou quelque chose qui permet de rapidement identifier c'est le top.
Vous pouvez m'aider ?

Merci
Nico
 

Pièces jointes

  • excel.jpg
    excel.jpg
    348.4 KB · Affichages: 11

vgendron

XLDnaute Barbatruc
avec un bout de code en plus pour colorer le mot Total (je n'arrive pas à colorer toute la ligne)
je ne maitrise vraiement pas les MFC

VB:
Sub Essai()
Dim Ligne As Long

Application.ScreenUpdating = False
With Sheets("A")
    LastLine = .Range("A" & .Rows.Count).End(xlUp).Row

    For Ligne = LastLine To 3 Step -1
        If .Range("A" & Ligne) <> .Range("A" & Ligne - 1) Then
            .Range("A" & Ligne).EntireRow.Insert
        End If
    Next Ligne
    
    LastLine = .Range("A" & .Rows.Count).End(xlUp).Row + 1
    TabData = .Range("A1").Resize(LastLine, 3).Value
    
    For i = LBound(TabData, 1) + 1 To UBound(TabData, 1)
        If TabData(i, 1) = "" Then
            TabData(i, 1) = "Total"
            TabData(i, 3) = Total
            Total = 0
        Else
            Total = Total + TabData(i, 3)
        End If
    Next i
    .Range("A1").Resize(LastLine, 3) = TabData
End With

Range("A2").Resize(LastLine, 3).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=A2=""Total"""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 49407
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Application.CutCopyMode = False

Application.ScreenUpdating = False
End Sub
 

Cousinhub

XLDnaute Barbatruc
avec un bout de code en plus pour colorer le mot Total (je n'arrive pas à colorer toute la ligne)
je ne maitrise vraiement pas les MFC
Hello,
@vgendron 😉
en finissant comme cela?
VB:
....
....
With Range("A2").Resize(LastLine, 3)
    .FormatConditions.Add Type:=xlExpression, Formula1:="=$A2=""Total"""
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 49407
        .TintAndShade = 0
    End With
End With
Application.ScreenUpdating = False
End Sub
Note l'adressage semi-relatif "$A2"
Bonne apm
 

Discussions similaires

Statistiques des forums

Discussions
312 145
Messages
2 085 762
Membres
102 966
dernier inscrit
InitialPP