Well this code does exactly the same as the 5-page lines of code you hade.
The only thing you need to do is rename the week sheets, Monday through Friday (withou the numbers to Monday (1) .... Friday (1) (notice the blank between the weekday and the first (
the code is this
Public Sub CreateJobs_Click()
Dim LastRow As Long
Dim weekLoop As Integer
Dim wsB As Worksheet '* variable for the Bookings worksheet
Dim wsWD As Worksheet '* variable for the applicable week worksheet week day
Dim wks As Integer
Dim dys As Integer
Dim dayName As String
Dim tSheet As String
Dim bTable As Object
Set bTable = Worksheets("Bookings").ListObjects("Table2")
bTable.Range.AutoFilter Field:=6
Application.ScreenUpdating = False
Set wsB = Worksheets("Bookings")
LastRow = wsB.Cells(Rows.Count, "B").End(xlUp).Row
For wks = 1 To numberOfWeeks
For dys = 1 To numberOfDays
dayName = Choose(dys, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
tSheet = dayName & " (" & wks & ")"
Application.StatusBar = tSheet
Set wsWD = Worksheets(tSheet)
wsWD.Range("B5", "D450").ClearContents
With bTable
.Range.AutoFilter Field:=6
.Range.AutoFilter Field:=6, Criteria1:=dayName & wks
End With
wsB.Range("B2:D450").Copy
wsWD.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Next dys
Next wks
ClearFilter_Click
Application.ScreenUpdating = True
Application.StatusBar = False
ClearFilter_Click
End Sub
This does not do anything new like keeping duplicates it's just you macro made efficient and.. I am still waiting for the answer to my question
IMPORTANT: insert a new VBA module and make sure the macros are Public (move the ClearFilter_Click macro to this project and make it public too)
Bookmarks