ich habe eine Datei, die verschiedene Tabellenblätter mit den Monatsnamen enthalten soll. Hierfür soll die ebenfalls enthaltene Vorlage inklusive deren Formatierungen jeweils auf das für ein neues Monat angelegte Tabellenblatt kopiert werden. Zugleich soll auf jedem neu angelegten Tabellenblatt der erste des Monats (z.B. 01.11.2016) in der Zelle "M3" hinterlegt sein. Diese Zelle ist in der Vorlage bereits als Datum formatiert. Damit ich diese nicht einzeln anlegen und kopieren muss, hatte ich die Hoffnung, dass es mit einer einfachen Formel funktionieren könnte. Allerdings bin ich bisher nur so weit gekommen. Und das funktioniert irgendwie nicht wie es soll...
Sub NeuerMonat()
Dim strFile As String
Dim lngCalc As Long
Dim lngTMP As Long
Dim D As Date
Dim i As Integer
Dim mZahl As Integer
Dim mWort As String
Dim yZahl As String
Dim dZahl As String
On Error GoTo Fin
For i = 1 To 2
D = "01.11.2016"
mZahl = Month(DateSerial(Year(D), Month(D) + i, 1))
mWort = Format(mZahl, "mmmm")
yZahl = Year(DateSerial(Year(D), Month(D) + i, 1))
dZahl = Day(DateSerial(Year(D), Month(D) + i, 1))
Debug.Print mZahl
Debug.Print mWort
Debug.Print yZahl
Debug.Print dZahl
strFile = ThisWorkbook.Path & Application.PathSeparator & "Vorlage.xltx"
With Application
.ScreenUpdating = False
.AskToUpdateLinks = False
.EnableEvents = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
.DisplayAlerts = False
End With
ThisWorkbook.Worksheets("Vorlage").visible = xlSheetVisible
ThisWorkbook.Worksheets("Vorlage").Copy After:=ThisWorkbook.Worksheets( _
Worksheets.count)
ThisWorkbook.Worksheets(Worksheets.count).name = mWort & " 2016"
ThisWorkbook.Worksheets(Worksheets.count).Cells(3, 13).Value = dZahl & "." & _
mZahl & "." & yZahl
Next i
Die Ausgabe mit Debug.Print ergibt allerdings folgendes:
12
Januar
2016
1
1
Dezember
2017
1
Somit passt der geschriebene Monat irgendwie nicht zum Monat in Zahlenform. Und den Inhalt der Zelle "M3" übernimmt es nicht als Datum.... Kann mir jemand weiterhelfen?Liebe Grüße
Gabi