Attaching an image for a better understanding of the issue:

Here, column A shows the dates, B has the daily amount, and C has the total amount of each day.
I want to stop the cumulative calculation at the end of each month based on column A and start recalculating the next month. As shown in the image.
I use the code below to find the end of the month and the first day of the month, assigning B = C, but I'm confused how I can start calculating the total amount from the next day for this month.
Appreciate if someone provides me with the logic to achieve this.
Sub MonthInt()
Dim MaxGain As Workbook
Dim DailyData As Worksheet
Dim n As Long, J As Long
Set MaxGain = Excel.Workbooks("MaxGain.xlsm")
Set DailyData = MaxGain.Worksheets("DailyData")
n = DailyData.Cells(Rows.Count, "A").End(xlUp).Row
DailyData.Range("B2") = DailyData.Range("C2")
For J = 3 To n
If DailyData.Range("A" & J) = Application.WorksheetFunction.EoMonth(DailyData.Range("A" & J), 0) Then
DailyData.Range("C" & J + 1) = DailyData.Range("B" & J)
End If
Next
End Sub
source
share