0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

マクロ2

0
Posted at

1ヶ月12シート作成

Sub CreateFiscalYearSheets()

Dim startDate As Date
Dim startYear As Long
Dim startMonth As Long
Dim i As Long
Dim ws As Worksheet
Dim newWS As Worksheet
Dim targetDate As Date

'★C3 の日付を年度開始として取得
startDate = Range("C3").Value
startYear = Year(startDate)
startMonth = Month(startDate)

'原紙シート
Set ws = ThisWorkbook.Worksheets("原紙")

For i = 0 To 11
    
    '対象月の1日
    targetDate = DateSerial(startYear, startMonth + i, 1)
    
    '原紙シートをコピー
    ws.Copy After:=Sheets(Sheets.Count)
    Set newWS = ActiveSheet
    
    'C3 に対象月の1日を入力
    newWS.Unprotect
    newWS.Range("C3").Value = targetDate
    newWS.Protect
    
    'シート名を YYYY.MM にする
    newWS.Name = Format(targetDate, "yyyy.mm")
    
Next i

End Sub

C3
=DATE(B2,4,1)

EOMONTH関数使ってるとこがB2

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?