문제 설명
TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)
=EDATE($A$46,‑5)
로 시작하는 범위가 있습니다. 여기서 A46은 =TODAY()
입니다. 이 범위는 5개의 추가 셀을 오른쪽으로 확장하며 각 셀에는 =EDATE(_cell to left_,1)
가 포함되고 월만 표시하도록 형식이 지정됩니다. 이렇게 하면 이전 6개월(즉, 1월, 2월, 3월, 4월, 5월, 6월)을 표시하는 왼쪽에서 오른쪽으로 전체 범위가 표시됩니다. 월 1일에 범위가 분명히 변경되어 현재 새 달과 그 뒤의 이전 5개월을 포함합니다.
달 아래의 각 셀에는 다음을 포함하는 데이터(수동으로 입력)가 있습니다. 계정에 대한 금액. 매월 1일 워크북을 펼쳤을 때, 데이터 셀에 있는 데이터를 잘라내고 추가된 새로운 추가 달을 설명하기 위해 한 열 뒤로 이동해야 합니다(가장 빠른 달이 이제 사라졌으므로 데이터도 사라져야 하기 때문입니다).
위 그림에서 알 수 있듯이 7월 1일에 2월, 3월, 4월, 5월 및 6월 데이터는 왼쪽으로 한 열입니다(1월이 해당 시점에서 사라지기 때문). 매월 1일에 발생하도록 동적이어야 합니다.
여기에 코드가 없어서 죄송합니다. 매월 1일을 기준으로 무엇을 시작해야 할지조차 모릅니다. 통합 문서는 현재 매크로를 사용할 수 있으며 매크로가 첨부되어 있습니다.
참조 솔루션
방법 1:
First you need a characteristic sign to recognize the new month.
This could be the day's number, but the first might be on a weekend ‑ so we need a better solution.</p>
I suggest to insert the headlines not by formula, but initially manual as date (still as full date, shown as monthname only). Then VBA code can compare the last cell's text with the current month's name.
If you place this code in the workbook's module, it runs on every opening of the file. It copies the range including headlines, inserts the new date in the last headline and clears the content below it.
I assumed the range shown in your image is A47 to F51. Please adapt it and the sheet's name to your needs.
Private Sub Workbook_Open()
Dim CurrentMonthname As String
Dim MsgAnswer As Integer
CurrentMonthname = MonthName(Month(Date), False) ' or Format(Date, "MMMM")
With Me.Sheets("AccountAmount")
If .Range("F47").Text <> CurrentMonthname Then
If MsgBox("Insert new month and move data?", _
vbQuestion + vbOKCancel, "New Month") = vbOK Then
.Range("A47:E51").Value = .Range("B47:F51").Value
.Range("F47").Value = Date
.Range("F48:F51").ClearContents
End If
End If
End With
End Sub