Forum Discussion

karlito2605's avatar
karlito2605
Copper Contributor
Oct 28, 2021
Solved

excel

Hello all, hope any of you can help me with a small issue that i have. I have cell A1 and A2 cell A1 has to add up numbers from cell A2 but cell A2 changes everyday and i want cell A1 to keep adding...
  • HansVogelaar's avatar
    HansVogelaar
    Oct 28, 2021

    karlito2605 

    You mentioned "it has to happen on the current date" so the code uses the current date. If you want to use the date in B1 instead, change the code to

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range
        If Target.CountLarge > 1 Then Exit Sub
        If Not Intersect(Range("B3,B20,B37,B54,B71"), Target) Is Nothing Then
            If IsNumeric(Target.Value) Then
                Application.EnableEvents = False
                Set rng = Target.Offset(0, 2).Resize(12, 1).Find(What:=Format(Range("B1").Value, "mmmm"), LookAt:=xlWhole)
                rng.Offset(0, 1).Value = Target.Value + rng.Offset(0, 1).Value
                Application.EnableEvents = True
            End If
        End If
    End Sub

Resources