BradleyS
Active Member
- Joined
- Oct 28, 2006
- Messages
- 351
- Office Version
- 2010
- Platform
- Windows
I have the following formula which checks the dates in column B are in a date period and then counts the unique numbers in column A and works fine.
Range("H8").Select
=SUMPRODUCT(IF((B2:B5<=J5)*(B2:B5>=I5), 1/COUNTIFS(B2:B5, "<="&J5, B2:B5, ">="&I5, A2:A5, A2:A5), 0))
However, I need to add another bit of criteria, which is to ignore any lines that have the words "NO DAY MATCH" in some of the cells in column E, so I have added this:
,--(E2:E5<>"NO DAY MATCH")
The full formula now looks like this. (Ctrl+Shift+Enter)
=SUMPRODUCT(IF((B2:B5<=J5)*(B2:B5>=I5), 1/COUNTIFS(B2:B5, "<="&J5, B2:B5, ">="&I5, A2:A5, A2:A5), 0),--(E2:E5<>"NO DAY MATCH"))"
However, it only works when entered manually into the Excel formula bar. When I use VBA it doesn't show anything in the cell and I can't work out why.
Selection.FormulaArray = "=SUMPRODUCT(IF((B2:B" & LR & "<=J5)*(B2:B" & LR & ">=I5), 1/COUNTIFS(B2:B" & LR & ", ""<=""&J5, B2:B" & LR & ", "">=""&I5, A2:A" & LR & ", A2:A" & LR & "), 0),--(E2:E" & LR & "<>""NO DAY MATCH""))"
I have even run a macro based on entering the formula, which gives me the code below but when I re-run the code it is still blank.
Range("H8").Select
Selection.FormulaArray = _
"=SUMPRODUCT(IF((R[-6]C[-6]:R[-3]C[-6]<=R[-3]C[2])*(R[-6]C[-6]:R[-3]C[-6]>=R[-3]C[1]), 1/COUNTIFS(R[-6]C[-6]:R[-3]C[-6], ""<=""&R[-3]C[2], R[-6]C[-6]:R[-3]C[-6], "">=""&R[-3]C[1], R[-6]C[-7]:R[-3]C[-7], R[-6]C[-7]:R[-3]C[-7]), 0),--(R[-6]C[-3]:R[-3]C[-3]<>""NO DAY MATCH""))"
Why does it only work if I enter the formula manually into Excel?
Is my formula wrong?
Table of data if it helps
Range("H8").Select
=SUMPRODUCT(IF((B2:B5<=J5)*(B2:B5>=I5), 1/COUNTIFS(B2:B5, "<="&J5, B2:B5, ">="&I5, A2:A5, A2:A5), 0))
However, I need to add another bit of criteria, which is to ignore any lines that have the words "NO DAY MATCH" in some of the cells in column E, so I have added this:
,--(E2:E5<>"NO DAY MATCH")
The full formula now looks like this. (Ctrl+Shift+Enter)
=SUMPRODUCT(IF((B2:B5<=J5)*(B2:B5>=I5), 1/COUNTIFS(B2:B5, "<="&J5, B2:B5, ">="&I5, A2:A5, A2:A5), 0),--(E2:E5<>"NO DAY MATCH"))"
However, it only works when entered manually into the Excel formula bar. When I use VBA it doesn't show anything in the cell and I can't work out why.
Selection.FormulaArray = "=SUMPRODUCT(IF((B2:B" & LR & "<=J5)*(B2:B" & LR & ">=I5), 1/COUNTIFS(B2:B" & LR & ", ""<=""&J5, B2:B" & LR & ", "">=""&I5, A2:A" & LR & ", A2:A" & LR & "), 0),--(E2:E" & LR & "<>""NO DAY MATCH""))"
I have even run a macro based on entering the formula, which gives me the code below but when I re-run the code it is still blank.
Range("H8").Select
Selection.FormulaArray = _
"=SUMPRODUCT(IF((R[-6]C[-6]:R[-3]C[-6]<=R[-3]C[2])*(R[-6]C[-6]:R[-3]C[-6]>=R[-3]C[1]), 1/COUNTIFS(R[-6]C[-6]:R[-3]C[-6], ""<=""&R[-3]C[2], R[-6]C[-6]:R[-3]C[-6], "">=""&R[-3]C[1], R[-6]C[-7]:R[-3]C[-7], R[-6]C[-7]:R[-3]C[-7]), 0),--(R[-6]C[-3]:R[-3]C[-3]<>""NO DAY MATCH""))"
Why does it only work if I enter the formula manually into Excel?
Is my formula wrong?
Table of data if it helps
Excel 2010 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | id | eventdate | code | read_term | CHECK | ||
2 | 5105 | 01/10/2018 | 9N | text | 7G1 | ||
3 | 7920 | 01/04/2018 | 9N | text | 8BC | ||
4 | 19714 | 31/12/2018 | 9N | text | NO DAY MATCH | ||
5 | 19714 | 01/04/2018 | 9N | text | NO DAY MATCH | ||
MS1 |
Last edited: