Vba to gray out weekends when dates are seperated.

LOZ1962

New Member
Joined
Dec 3, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I have a year to view calendar,in a grid format 31 days accross the top & months down the a: column I would like to use VBA to grey out weekends. I have tried every formula I can find with very limited success as they do not know what year or month it is. They grey out days 6/7 in all months.. 4 days I've been trying to do this Thanks for looking & any help given. Regards Loz Baker (58 years old & still learning.)
 

Attachments

  • Holidate.jpg
    Holidate.jpg
    168.3 KB · Views: 24

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi & welcome to MrExcel.
How about
+Fluff v2.xlsm
ABCDEFGHIJKLMNOPQR
1
220201234567891011121314151617
3January
4February
5March
6April
7May
8June
9July
10August
11September
12October
13November
14December
Data
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B3:R14Expression=WEEKDAY(DATE($A$2,MONTH($A3&1),B$2),2)>5textNO
 
Upvote 0
I was working on a reply, saying that you do not need VBA, you can simply use Conditional Formatting, and was getting ready to reply, when I see that Fluff had posted the same solution in the time it took me to come up with the formula. The only difference was the Conditional Formatting formula I came up with was a little different, but both should work.

Here was my formula:
Excel Formula:
=WEEKDAY(DATEVALUE($A3 & " " & B$2 & ", " & $A$2),2)>5

Just make sure that you select the range A3:BF14 before applying the Conditional Formatting, and it will apply to every cell in your range.
 
Upvote 0
Thank you so much guys Works a treat! another little thing can this be run in VBA coding :)
 
Upvote 0
can this be run in VBA coding
Conditional Formatting runs automatically, so once set up is maintenance free.

However, if you want to set up this Conditional Formatting via VBA, simply turn on your Macro Recorder while you record yourselves doing the CF steps manually.
Then stop the Recorder when finished, and you will have the VBA code you need to do this.
 
Upvote 0
Oh God so simple, thanks again guys, now I can get back to my proper job.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Good afternoon

I have managed to get Bank holidays included in the Spreadsheet but cannot think how to black out non dates eg: 31st Sept & 31st November
 

Attachments

  • Holidays v2.4.jpg
    Holidays v2.4.jpg
    151.4 KB · Views: 9
Upvote 0
How about
Excel Formula:
=OR(WEEKDAY(DATE($A$2,MONTH($A3&1),B$2),2)>5,DAY(EOMONTH(DATE($A$2,MONTH($A3&1),$B$2),0))<B$2)
 
Upvote 0
Thanks that works great, but I'd like the Non dates blacked out and not the same color as the weekends , please.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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