Auto Date Columns relative to the Worksheet Name

JMB_0159

New Member
Joined
Jul 7, 2009
Messages
24
Hi, I am after some help in creating an XL (2013) file which will enable me to create a Workbook with Worksheet tab names of Months of the year, also it will add the dates for that particular Month to row 2 within this worksheet. The worksheet will have Personnel Names in column A and the date ranges for that month start from column C. If anyone can help out it would be appreciated. The aim is to have the Jobs / Job Numbers allocated to personnel on particular days therefore I can keep track also holidays, RDO's etc.

Thanks in anticipation
James
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi
Is this what you're after
Code:
Sub NewBk()

    Dim Cnt As Long
    Dim Shts As Long
    
Application.ScreenUpdating = False

    Shts = Application.SheetsInNewWorkbook

    Application.SheetsInNewWorkbook = 12
    Workbooks.Add
    Application.SheetsInNewWorkbook = Shts
    
    For Cnt = 1 To 12
        With Sheets(Cnt)
            .Range("C2").NumberFormat = "@"
            .Range("C2") = Format("1/" & Cnt & "/2017", "dd/mm/yyyy")
            .Name = Format(.Range("c2"), "MMM")
            Select Case Cnt
                Case 1, 3, 5, 7, 8, 10, 12
                    With .Range("D2").Resize(, 30)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 2
                    With .Range("D2").Resize(, 27)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 4, 6, 9, 11
                    With .Range("D2").Resize(, 29)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
            End Select
            .Rows(2).NumberFormat = "dd/mm/yyyy"
        End With
    Next Cnt

End Sub
 
Upvote 0
Thanks very much worked perfectly.
Just another question could this macro be modified to highlight weekends e.g. sat & sun columns light grey ?
 
Upvote 0
With minor modification to above code by Fluff . :)



Code:
Sub NewBk()


    Dim Cnt As Long
    Dim Shts As Long
    
Application.ScreenUpdating = False


    Shts = Application.SheetsInNewWorkbook


    Application.SheetsInNewWorkbook = 12
[B]    Set NewBk2 = Workbooks.Add[/B]
  
  
    For Cnt = 1 To 12
        
        With[B] NewBk2.[/B]Sheets(Cnt)
            .Range("C2").NumberFormat = "@"
            .Range("C2") = Format("1/" & Cnt & "/2017", "dd/mm/yyyy")
            .Name = Format(.Range("c2"), "MMM")
            Select Case Cnt
                Case 1, 3, 5, 7, 8, 10, 12
                    With .Range("D2").Resize(, 30)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 2
                    With .Range("D2").Resize(, 27)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 4, 6, 9, 11
                    With .Range("D2").Resize(, 29)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
            End Select
[B]            .Rows(2).NumberFormat = "dd/mm/yyyy"[/B]

[B]            .Range("c2").FormatConditions.Delete[/B]
[B]            .Range("c2").FormatConditions.Add Type:=xlExpression, Formula1:="=WEEKDAY(C2,2)>5"[/B]
[B]            .Range("c2").FormatConditions(1).Interior.ColorIndex = 15[/B]
[B]            .Range("c2").Copy[/B]
[B]            .Range(.Cells(2, 3), .Cells(2, 31)).PasteSpecial (xlPasteFormats)[/B]
        End With
         
        Next Cnt


    End Sub
 
Upvote 0
Excellent, I know I am stretching the friendship but would it be possible to code so that when I run the macro it will not create another workbook.

Once again thanks
James
 
Upvote 0
No worries . I hope this will work fine.


Code:
Sub SameBk()


    Dim Cnt As Long
    Dim Shts As Long
    
Application.ScreenUpdating = False


    With ThisWorkbook
    For Cnt = 1 To 12
        If Cnt > .Worksheets.Count Then .Worksheets.Add after:=Sheets(Sheets.Count)
        With Sheets(Cnt)
            .Range("C2").NumberFormat = "@"
            .Range("C2") = Format("1/" & Cnt & "/2017", "dd/mm/yyyy")
            .Name = Format(.Range("c2"), "MMM")
            Select Case Cnt
                Case 1, 3, 5, 7, 8, 10, 12
                    With .Range("D2").Resize(, 30)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 2
                    With .Range("D2").Resize(, 27)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
                Case 4, 6, 9, 11
                    With .Range("D2").Resize(, 29)
                        .Formula = "=rc[-1]+1"
                        .Value = .Value
                    End With
            End Select
            .Rows(2).NumberFormat = "dd/mm/yyyy"
          
            .Range("c2").FormatConditions.Delete
            .Range("c2").FormatConditions.Add Type:=xlExpression, Formula1:="=WEEKDAY(C2,2)>5"
            .Range("c2").FormatConditions(1).Interior.ColorIndex = 15
            .Range("c2").Copy
            ThisWorkbook.Worksheets(1).Range(ThisWorkbook.Worksheets(1).Cells(2, 1), ThisWorkbook.Worksheets(1).Cells(2, 31)).PasteSpecial
        End With
    Next Cnt
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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