First of all, my apologies to the community for bringing the same macro multiple times. I'm just incapable of figuring this out.. I solved one thing and then another aspect (which I don't even think I have touched) stopped working. On the code below, everything works flawless on my Macbook but not so much on my colleagues windows computer. Specifically, it is the:
"ws.Range("A1") = NextMonth"
found in the "Else" section that seems not to be working. Ironically, it did work earlier but then the sheet name (month) was in the wrong language (another post). For some unreason the latter issue was resolved and then the first-mentioned issue appeared.. such a mess!
The only thing I have done to the sheet that is not visible is changing the format of the A1 cell to "[$-en-GB] MMMM ¯¯¯¯", which is to make sure the month in "A1" appears in english.
Any suggestions?
Regards, Alexander
Sub MonthlyReport()
Dim CurrentMonth As String
Dim CurrentYear As String
Dim NextMonth As String
Dim ws As Worksheet
Dim ExtractMonth As String
Dim ExtractYear As String
Sheets(Sheets.Count).Select
Set ws = ActiveSheet
If ws.Range("A1") = "" Then
CurrentMonth = Application.InputBox("Please enter the month", "Report (monthly)")
CurrentYear = Application.InputBox("Please enter the year", "Report (monthly)")
Sheets("Template").Visible = True
Sheets("Template").Copy After:=Sheets(Sheets.Count)
Sheets("Template").Visible = False
Sheets(Sheets.Count).Select
Set ws = ActiveSheet
ws.Range("A1") = CurrentMonth & " " & CurrentYear
ws.Name = CurrentMonth
ws.Range("C96") = "Average " & CurrentMonth & " " & CurrentYear
Else
CurrentMonth = ws.Range("A1")
NextMonth = DateAdd("m", 1, CurrentMonth)
Sheets("Template").Visible = True
Sheets("Template").Copy After:=Sheets(Sheets.Count)
Sheets("Template").Visible = False
Sheets(Sheets.Count).Select
Set ws = ActiveSheet
ws.Range("A1") = NextMonth
ExtractMonth = Format(NextMonth, "mmmm")
ExtractYear = Format(NextMonth, "yyyy")
ws.Name = ExtractMonth
ws.Range("C96") = "Average " & ExtractMonth & " " & ExtractYear
End If
End Sub