Count instances of dates across range of cells (not cells which contain dates)

ellison

Active Member
Joined
Aug 1, 2012
Messages
356
Office Version
  1. 365
Platform
  1. Windows
Hi, we are trying to tidy up some data and are trying to count instances of dates across a range of cells.
Previously we counting cells which contain dates (using countif as below) but there was lots of info not being captured.
Is it possible to find a way of doing this?

It may be worth me saying that one of the challenges we have is that some of the cells contain over 255 characters which can cause some formulas / macros to fall over
(PS we are trying to put some controls in place to stop the info cells being so long, but that's for the future! )


rowInfo-1Info-2Info-3Info-4Info-5Count-Cells-FormulaNotes
2redblue11/06/2023 sold 10/11/2023 sold11/06/2023 bought 11/06/2023new source needed 11/06/20233 cells = COUNTIF(B2:F2,"*/??/*")5 occurrences of dates, sometimes dates are in the middle of a cell
3Essex11/06/2023 herts 11/06/2023 move11/06/2023 essex3 cells = COUNTIF(B2:F2,"*/??/*")3 occurrences of dates, sometimes there are blanks in the info
411/06/2023 herts11/06/2023 herts3 cells = COUNTIF(B2:F2,"*/??/*")2 occurrences of dates, sometimes there are duplicates in the info
5111/06/20233 cells = COUNTIF(B2:F2,"*/??/*")1 occurrence of date, sometimes the cells in the info are numeric


Huge thanks for any help

All the best
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Is this what you want?
Book1
ABCDEFGH
1rowInfo-1Info-2Info-3Info-4Info-5Count-Cells-FormulaNotes
22redblue11/06/2023 sold 10/11/2023 sold11/06/2023 bought 11/06/2023new source needed 11/06/202355 occurrences of dates, sometimes dates are in the middle of a cell
33Essex11/06/2023 herts 11/06/2023 move11/06/2023 essex33 occurrences of dates, sometimes there are blanks in the info
4411/06/2023 herts11/06/2023 herts22 occurrences of dates, sometimes there are duplicates in the info
5514508801 occurrence of date, sometimes the cells in the info are numeric
Sheet1
Cell Formulas
RangeFormula
G2:G5G2=COUNTIF(B2:F2,"*"&"*")
 
Upvote 0
I can imagine problems with this suggested code but with your limited sample, it seems to work. To use, drag = LoopOverRange(D1:F1) down a column (using your own range inputs)
VBA Code:
Function LoopOverRange(rng As Range) As Integer
Dim cel As Range, ary As Variant, intCount As Integer

For Each cel In ActiveSheet.Range(rng.Address)
     If cel Like "*/??/*" Then
          ary = Split(cel, "/")
          intCount = intCount + UBound(ary)
          LoopOverRange = intCount / 2
     End If
Next

End Function
Code goes into a standard module (at least that's where I put it).
EDIT - using data like this
2​
redblue11/06/2023 sold 10/11/2023 sold11/06/2023 bought 11/06/2023new source needed 11/06/20235
3​
Essex11/06/2023 herts 11/06/2023 move11/06/2023 essex3
4​
11/06/2023 herts11/06/2023 herts1
5​
1
11/06/23​
/
 
Upvote 0
Solution
Cor dear, bosses - they're never quite satisfied are they!?!

I've now just been asked if it would be possible to build on this solution by seeing if it would be possible for the macro to cope with checking for specific dates (located in Row 1) across the range.

Please see a small snapshot of data to help illustrate...


rowInfo-1Info-2Info-3Info-4Info-5Dates:31/05/201901/01/202008/11/202114/12/202101/06/202311/06/202325/08/2023
2redblue11/06/2023 sold 10/11/2023 sold01/06/2023 bought 11/05/2022new source needed 14/12/20210001110
3Essex31/05/2019 herts 08/01/2023 move08/11/2021 essex1010000
411/06/2023 herts01/01/2020 herts0100010
5111/06/2023allocated 25/08/2023 gone 11/06/2023 all sold 11/06/2023 stock sourced0000031


If any questions, please just holler

With thanks
 
Upvote 0
checking for specific dates (located in Row 1) across the range.
That means checking a date in one cell - looks like H1 in your sample (31/05/2019)
" checking for specific dates" is kind of vague, but should be possible.
 
Upvote 0
Thanks for checking…
The dates will be in row 1.
So in the example above, they’d be in cells:
H1
I1
J1
K1
L1

Hope that helps …
 
Upvote 0
Hi, I was just wondering if I should start a new thread for this (new) follow-up question ??

(And then tick the "solved" for your (brilliant!) answer to the first question ...)
 
Upvote 0
Hi, I was just wondering if I should start a new thread for this (new) follow-up question ??
I thinks this is a direct follow-on so could stay here.
What about this?

23 06 14.xlsm
BCDEFGHIJKLMN
1Info-1Info-2Info-3Info-4Info-5Dates:31/05/20191/01/20208/11/202114/12/20211/06/202311/06/202325/08/2023
2redblue11/06/2023 sold 10/11/2023 sold01/06/2023 bought 11/05/2022new source needed 14/12/20210001110
3Essex31/05/2019 herts 08/01/2023 move08/11/2021 essex1010000
411/06/2023 herts01/01/2020 herts0100010
5111/06/2023allocated 25/08/2023 gone 11/06/2023 all sold 11/06/2023 stock sourced0000031
Check Dates (1)
Cell Formulas
RangeFormula
H2:N5H2=LET(s,CONCAT(TEXT($B2:$F2,"dd/mm/yyyy")),(LEN(s)-LEN(SUBSTITUTE(s,TEXT(H$1,"dd/mm/yyyy"),"")))/10)
 
Upvote 0
arggghhhhh so close to being perfect!

It works, but then falls down on cells which have more than 244 characters.

Is there are a different workaroud maybe?
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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