Forum Discussion

GKE2019's avatar
GKE2019
Brass Contributor
Apr 11, 2022
Solved

Change weekend collumn background colour

Hello,

 

I would like to change the background colour if the date says it is weekend.

I now have this:

It works but for a bit, I would like that only the weekends are highlighted.

And that it would stop when there is no more string/text found at A.

 

Right now I use this code

 

 

Dim r As Range, c As Range
Set r = Range(Range("G2"), Range("NG2").End(xlDown))
For Each c In r
If Weekday(c) = 6 Or Weekday(c) = 7 Then
c.Interior.ColorIndex = 3
End If
Next c

 

 

What can I do to make it work?

  • GKE2019 No need for a macro. Use Conditional Formatting in stead. 

    Select the range you want to affect , including the date header. On the Home ribbon, select Conditional formatting. Add a new rule using a formula like this:

     

    =WEEKDAY(B$2)>=6

     

    Where B2 is the first date in the top left corner (see picture).

     

1 Reply

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    GKE2019 No need for a macro. Use Conditional Formatting in stead. 

    Select the range you want to affect , including the date header. On the Home ribbon, select Conditional formatting. Add a new rule using a formula like this:

     

    =WEEKDAY(B$2)>=6

     

    Where B2 is the first date in the top left corner (see picture).