날짜가 여러 시트 인 MM2D 형식의 통합 문서가 있습니다. 이 매크로는 모든 날짜 시트 (01OCT, 02OCT, .... 30OCT와 같은)를 선택하여 범위를 선택하고 새 시트로 복사해야합니다.날짜로 정의 된 시트 선택
세포를 선택하고 복사하면 실제로 문제가되지 않으며 완벽하게 작동합니다. 그러나 시트 이름을 정의하는 데 문제가 있습니다. 나는 처음에 InputBox를 사용하여 달과 달의 일 수를 정의하는 사용자를 원합니다.
그래서 사용자가 month = "FEB"및 DaysMonth = 28을 선택하면 01FEB, 02FEB, 03FEB, ... 28FEB라는 트로프 시트가 반복됩니다.
Sub Merge_whole_month()
Application.ScreenUpdating = False
Dim month As String
month = InputBox(Prompt:="Please enter month in format MMM", _
Title:="Month")
Dim DaysMonth As Long
DaysMonth = InputBox(Prompt:="Please enter number of days in month", _
Title:="Days")
'create new sheet for results
Sheets.Add.Name = "Merge"
'loop
For i = 1 To DaysMonth
i = Format(i, "##")
Sheets(i & month).Activate 'here is the problem
'select cell G3, then all "non-empty" cells to the right and down and COPY
Range(Range("G3", Range("G3").End(xlToRight)), Range("G3", Range("G3").End(xlToRight)).End(xlDown)).Select
Selection.Copy
Sheets("Merge").Activate 'activate sheet where cells needs to be copied
'find last cell in 2nd row in sheet
lastCol = Cells(2, Columns.Count).End(xlToLeft).Column
lastCol = lastCol + 1
Cells(1, lastCol) = i & month 'log date and month in cell above
Cells(2, lastCol).Select
ActiveSheet.Paste 'Paste
Next i
Application.ScreenUpdating = True
End Sub
사전 도움을 주셔서 감사합니다.
정수로 * i *를 사용하여 'For ... Next'를 증가시키고 문자열 중간 스트림으로 바꿔서는 안됩니다. 'Sheets (Format (i, "00") & month) .Activate와 같은 것을 사용하여 워크 시트를 선택하십시오. * i *의 다른 조작을 제거하십시오. – Jeeped