Adding a sheet every month and stop in 2019

fluxcapacitr609

New Member
Joined
Feb 21, 2018
Messages
24
This code works great. It creates a new sheet every month. I just want it to stop adding once we get to 2019. Any Ideas?




Code:
Sub AddMonthWkst()
Dim ws As Worksheet
Dim strName As String
Dim bcheck As Boolean


On Error Resume Next
strName = Format(Date, "mmm_yyyy")
bcheck = Len(Sheets(strName).Name) > 0


If bcheck = False Then
    Set ws = Worksheets.Add(Before:=Sheets(1))
    ws.Name = strName
End If


End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try

Code:
Sub AddMonthWkst()
Dim ws As Worksheet
Dim strName As String
Dim bcheck As Boolean

On Error Resume Next
strName = Format(Date, "mmm_yyyy")
bcheck = Len(Sheets(strName).Name) > 0

If bcheck = False And Right(strName, 4) < 2019 Then
    Set ws = Worksheets.Add(Before:=Sheets(1))
    ws.Name = strName
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,790
Messages
6,174,600
Members
452,574
Latest member
hang_and_bang

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top