Setting the background color for weekends

DChambers

Active Member
Joined
May 19, 2006
Messages
257
I am using the following code to create a spreadsheet that has all the days of the week for that month and would like to set the background color for both Saturday and Sunday to gray, any Ideas?
Code:
' Put in the first day of the current month
    ws.Range("A8").Value = DateSerial(Year(Date), Month(Date), 1)
 
' AutoFill Column "A" with all the dates of the month
    ws.Range("A8").AutoFill Destination:=ws.Range("A8").Resize(DateSerial(Year(Date), Month(Date) + 1, 1) - DateSerial(Year(Date), Month(Date), 1))
 
' AutoFill Column "B" with the days of the week
    ws.Range("B8").Resize(DateSerial(Year(Date), Month(Date) + 1, 1) - DateSerial(Year(Date), Month(Date), 1)).Formula = "=TEXT(A8,""DDDD"")"
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You can get the number of days in the month like this:

Day(DateSerial(Year(Date), Month(Date) + 1, 0))

and here's another way to get the first day of the month:
Date - Day(Date) + 1

Why not use Conditional Formatting?

Select cell A8:B38 and use the following Conditional Formatting formula:
=AND($A8<>"",WEEKDAY($A8,2)>5)
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

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