Copying and creating new tabs with VBA

RobbieL

Board Regular
Joined
Oct 4, 2007
Messages
109
Hi all,

Very grateful if anyone can give me some pointers on how best to do this. I've created a worksheet that people will use to log their entry and exit times during the day.

There is a master sheet which will be blank. I then want a tab for each month named "week commencing dd-mmm-yy". Each tab needs to have a date that is 4 weeks on from the next, and ideally, won't be created until cell G33 is completed on the current tab.

Is there a way to do this relatively simply?

Many thanks in advance.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi,

Maybe a sheet change event such as:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim datCur As Date
Dim iSheet As Integer, iPtr As Integer
Dim sCurName As String
Dim wsCur As Worksheet

If Target.Resize(1, 1).Address = "$G$33" Then
    For iPtr = 0 To 3
        datCur = Date + (iPtr * 28)
        sCurName = "Week Commencing " & Format(datCur, "dd-mmm-yy")
        With ThisWorkbook
            Set wsCur = Nothing
            On Error Resume Next
            Set wsCur = .Sheets(sCurName)
            On Error GoTo 0
            If wsCur Is Nothing Then
                iSheet = ThisWorkbook.Sheets.Count
                Set wsCur = .Sheets.Add(after:=.Sheets(iSheet))
                wsCur.Name = sCurName
            End If
        End With
    Next iPtr
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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