Need help with VBA formatting of date

ajc623

Board Regular
Joined
Nov 8, 2013
Messages
57
Fairly new to using the more advanced features in excel and need help. What I have is a workbook with the daily schedule for several employees and at the end of each day I print the schedule in 3 different formats and then want to save the sheet by copying in and renaming it with the next work day as the name in mmddyy format. Below is what I have which works great except I can figure out how to have the date be the next workday (M-F) and not just today. Thanks

Sheets("Today").Copy Before:=Sheets(9)
Sheets("Today (2)").Select
Sheets("Today (2)").Name = Format(Date, mmddyy)

Andrew
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
you almost had it

no need to select a worksheet to rename it

as a sidenote : same with cells, no need to select cells to work with them

Code:
Sub test()


    Sheets("Today").Copy Before:=Sheets(9)


    Sheets("Today (2)").Name = Format(Date[COLOR=#ff0000] + 1[/COLOR], [COLOR=#ff0000]"[/COLOR]mmddyy[COLOR=#ff0000]"[/COLOR])


End Sub
 
Upvote 0
You forgot about the next work day. This should work.

Code:
    NextWorkDay = Date + 1
    'increment NextWorkDay if it is a weekend
    If Weekday(NextWorkDay, vbMonday) > 5 Then
        While Weekday(NextWorkDay, vbMonday) > 5
            NextWorkDay = NextWorkDay + 1
        Wend
    End If
    Sheets("Today").Copy Before:=Sheets(9)
    Sheets("Today (2)").Name = Format(NextWorkDay, mmddyy)
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,643
Members
449,093
Latest member
Ahmad123098

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