Hi,
I'm working on dynamic calendar that has weekends and Bank Holidays conditionally formatted (highlighted)
I'm struggling with formula that would sum values each week depending if it's normal weekday, weekend or Bank Holiday
I have 4 conditional formatting rules in this order
grey out days that don't belong to current month
highlight bank holidays in orange
highlight weekends in green
highlight weekdays in white
I have been using VBA for summing conditional formatted cells
Function SumConditionColorCells(CellsRange As Range, ColorRng As Range)
Dim Bambo As Boolean
Dim dbw As String
Dim CFCELL As Range
Dim CF1 As Single
Dim CF2 As Double
Dim CF3 As Long
Bambo = False
For CF1 = 1 To CellsRange.FormatConditions.Count
If CellsRange.FormatConditions(CF1).Interior.ColorIndex = ColorRng.Interior.ColorIndex Then
Bambo = True
Exit For
End If
Next CF1
CF2 = 0
CF3 = 0
If Bambo = True Then
For Each CFCELL In CellsRange
dbw = CFCELL.FormatConditions(CF1).Formula1
dbw = Application.ConvertFormula(dbw, xlA1, xlR1C1)
dbw = Application.ConvertFormula(dbw, xlR1C1, xlA1, , ActiveCell.Resize(CellsRange.Rows.Count, CellsRange.Columns.Count).Cells(CF3 + 1))
If Evaluate(dbw) = True Then CF2 = CF2 + CFCELL.Value
CF3 = CF3 + 1
Next CFCELL
Else
SumConditionColorCells = ""
Exit Function
End If
SumConditionColorCells = CF2
End Function
now my issue:
helper column should only sum weekdays (exclude Bank Holidays) but even if I reference in formula to cell with white colour, it still takes value of cell that is coloured in orange (Bank Holiday)
is there another way to sum values of cells but their formatted colour? Does my udf needs amending?
my mini sheets shows manually entered values in columns BN to BR to show what I need the formula to calculate, with the ability to adapt to a different month (and different allocation of Bank Holiday in a week - Monday, Friday, Thursday)
Can you please guise where to start editing
Thank you
I'm working on dynamic calendar that has weekends and Bank Holidays conditionally formatted (highlighted)
I'm struggling with formula that would sum values each week depending if it's normal weekday, weekend or Bank Holiday
I have 4 conditional formatting rules in this order
grey out days that don't belong to current month
highlight bank holidays in orange
highlight weekends in green
highlight weekdays in white
I have been using VBA for summing conditional formatted cells
Function SumConditionColorCells(CellsRange As Range, ColorRng As Range)
Dim Bambo As Boolean
Dim dbw As String
Dim CFCELL As Range
Dim CF1 As Single
Dim CF2 As Double
Dim CF3 As Long
Bambo = False
For CF1 = 1 To CellsRange.FormatConditions.Count
If CellsRange.FormatConditions(CF1).Interior.ColorIndex = ColorRng.Interior.ColorIndex Then
Bambo = True
Exit For
End If
Next CF1
CF2 = 0
CF3 = 0
If Bambo = True Then
For Each CFCELL In CellsRange
dbw = CFCELL.FormatConditions(CF1).Formula1
dbw = Application.ConvertFormula(dbw, xlA1, xlR1C1)
dbw = Application.ConvertFormula(dbw, xlR1C1, xlA1, , ActiveCell.Resize(CellsRange.Rows.Count, CellsRange.Columns.Count).Cells(CF3 + 1))
If Evaluate(dbw) = True Then CF2 = CF2 + CFCELL.Value
CF3 = CF3 + 1
Next CFCELL
Else
SumConditionColorCells = ""
Exit Function
End If
SumConditionColorCells = CF2
End Function
now my issue:
helper column should only sum weekdays (exclude Bank Holidays) but even if I reference in formula to cell with white colour, it still takes value of cell that is coloured in orange (Bank Holiday)
is there another way to sum values of cells but their formatted colour? Does my udf needs amending?
my mini sheets shows manually entered values in columns BN to BR to show what I need the formula to calculate, with the ability to adapt to a different month (and different allocation of Bank Holiday in a week - Monday, Friday, Thursday)
Can you please guise where to start editing
Thank you
Book1 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AU | AV | AW | AX | AY | BF | BG | BH | BI | BJ | BK | BL | BM | BN | BO | BP | BQ | BR | BS | BT | BU | BV | BW | BX | |||||||||
1 | ||||||||||||||||||||||||||||||||
2 | 20/03/2024 | 21/03/2024 | 22/03/2024 | 23/03/2024 | 24/03/2024 | 25/03/2024 | 26/03/2024 | 27/03/2024 | 28/03/2024 | 29/03/2024 | 30/03/2024 | 31/03/2024 | Total O/T | helper | O/T @ flat rate | O/T @ 1.5 | Weekend | Bank Holiday | bank holidays | |||||||||||||
3 | 5 | 3 | 6 | 7 | 21.00 | 8 | 0 | 7 | 6 | 01/01/2024 | ||||||||||||||||||||||
4 | 29/03/2024 | |||||||||||||||||||||||||||||||
5 | 01/04/2024 | |||||||||||||||||||||||||||||||
6 | 06/05/2024 | |||||||||||||||||||||||||||||||
7 | 27/05/2024 | |||||||||||||||||||||||||||||||
8 | 26/08/2024 | |||||||||||||||||||||||||||||||
9 | ||||||||||||||||||||||||||||||||
10 | ||||||||||||||||||||||||||||||||
11 | ||||||||||||||||||||||||||||||||
12 | ||||||||||||||||||||||||||||||||
13 | ||||||||||||||||||||||||||||||||
14 | ||||||||||||||||||||||||||||||||
15 | ||||||||||||||||||||||||||||||||
16 | ||||||||||||||||||||||||||||||||
jan |
Cell Formulas | ||
---|---|---|
Range | Formula | |
BF2:BL2 | BF2 | =SEQUENCE(,7,AY2+1,1) |
BM3 | BM3 | =SUM(BF$3:BL$3) |
BP3 | BP3 | =IF($C3=$D3,$N3,$N3-$O3) |
Dynamic array formulas. |
Cells with Conditional Formatting | ||||
---|---|---|---|---|
Cell | Condition | Cell Format | Stop If True | |
F2:BL60 | Expression | =MONTH(F$2)<>MONTH($U$2) | text | NO |
BF2:BL60 | Expression | =ISNUMBER(VLOOKUP(BF$2,$BW$3:$BW$8,1,0)) | text | NO |
AF2:AL60,AS2:AY60,BF2:BL60,S2:Y60,F2:L60 | Expression | =WEEKDAY(F$2,2)>5 | text | NO |
AF2:AL60,AS2:AY60,BF2:BL60,S2:Y60,F2:L60 | Expression | =OR(WEEKDAY(F$2)=2,WEEKDAY(F$2)=3,WEEKDAY(F$2)=4,WEEKDAY(F$2)=5,WEEKDAY(F$2)=6) | text | NO |
Cells with Data Validation | ||
---|---|---|
Cell | Allow | Criteria |
BF2:BL60 | Custom | =MONTH(AZ2)<>MONTH($AY$2) |
BM2 | Any value | |
BM3:BM60 | Custom | =MONTH(BM2)<>MONTH($AY$2) |