TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)


문제 설명

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일 워크북을 펼쳤을 때, 데이터 셀에 있는 데이터를 잘라내고 추가된 새로운 추가 달을 설명하기 위해 한 열 뒤로 이동해야 합니다(가장 빠른 달이 이제 사라졌으므로 데이터도 사라져야 하기 때문입니다).

enter image description here

위 그림에서 알 수 있듯이 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

(by eyeScreamAsger)

참조 문서

  1. Moving a range based on TODAY() function and first of the month (CC BY‑SA 2.5/3.0/4.0)

#vba #excel






관련 질문

열에 문자열이 포함된 경우 열 번호 나열 (List column numbers if columns contain string)

SpinButton SpinUp 또는 SpinDown 새로 고침 (Refreshing SpinButton SpinUp or SpinDown)

변수를 사용하여 Excel VBA에서 3차원 배열 요소에 액세스 (Use variables to access 3 dimensional array elements in Excel VBA)

TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)

ALV 레이아웃의 표시된 모든 열을 제거하는 방법 (How to remove all displayed columns of ALV layout)

셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)

Excel VBA의 세로 열에 여러 json을 생성하는 방법은 무엇입니까? (How to generate multiple json in vertical column in Excel VBA?)

공개 함수의 VBA 런타임 오류 -2147319767(80028029) (VBA Run-time error -2147319767 (80028029) in Public Function)

알 수 없는 수의 문자를 패턴 일치시키는 방법 (How to Pattern Match an Unknown Number of Characters)

Excel VBA 파일이 열려 있는지 확인 기능 (Excel VBA Check if File is open function)

ActiveCell..Offset(-1,0)=을 사용하는 If/And/Then/Else 문의 VBA 문제= (VBA Issue with If/And/Then/Else statement using ActiveCell..Offset(-1,0)=)

VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application-defined or Object-defined error" setting cell contents)







코멘트