Sub ComprehensiveMonthlyUpdateRevised()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Checking")
' Dynamically update the month names in H20:M20 and shift values for H21:M22
Dim currentMonth As Date
currentMonth = Date ' Today's date to determine the current month
Dim currentMonthName As String
currentMonthName = Format(currentMonth, "mmmm")
Dim prevMonthName As String
prevMonthName = Format(DateAdd("m", -1, currentMonth), "mmmm")
ws.Cells(20, 8).Value = Format(DateAdd("m", -3, currentMonth), "mmmm")
ws.Cells(20, 10).Value = Format(DateAdd("m", -2, currentMonth), "mmmm")
ws.Cells(20, 12).Value = Format(DateAdd("m", -1, currentMonth), "mmmm")
ws.Cells(20, 13).Value = currentMonthName
For i = 8 To 11
ws.Cells(21, i).Value = ws.Cells(21, i + 2).Value
ws.Cells(22, i).Value = ws.Cells(22, i + 2).Value
Next i
ws.Cells(21, 13).Formula = "=H17"
ws.Cells(22, 13).Formula = "=ABS(SUM(H5:I16))"
' Revised logic for K39:L50 based on the new requirements
Dim monthRow As Long
Dim foundCurrentMonth As Boolean
foundCurrentMonth = False
For monthRow = 39 To 50
If ws.Cells(monthRow, 11).Value = currentMonthName And Not foundCurrentMonth Then
ws.Cells(monthRow, 12).Formula = "=E350"
foundCurrentMonth = True
ElseIf ws.Cells(monthRow, 11).Value = prevMonthName Then
ws.Cells(monthRow, 12).Value = ws.Cells(350, 5).Value
End If
Next monthRow
....................
Truncated for Display