Count maximum no. of consecutive NULL OR BLANK cells between two date fields

Millixcel

New Member
Joined
Jun 24, 2020
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
I need to:
  1. return the maximum number of consecutive blank or null cells between the start and end date
  2. return the max date that corresponds to the end of the above sequence
Things to be aware of: There will sometimes be multiple occurrences of blank/null sequences.

I got close using Max, Frequency and Column but it went to pieces when trying to calculate between the two dates only.

Please see below where I have tried to use the MrExcel add in to provide example data

Excel forum example.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
2Return the max count of consecutive NULL OR BLANK values between the start and end dates
3Return the max date which corresponds to the above sequence
4
5START_DATEEND_DATECONSECEND OF SEQUENCE01/01/201801/02/201801/03/201801/04/201801/05/201801/06/201801/07/201801/08/201801/09/201801/10/201801/11/201801/12/201801/01/201901/02/201901/03/201901/04/201901/05/201901/06/201901/07/201901/08/201901/09/201901/10/201901/11/201901/12/201901/01/202001/02/202001/03/202001/04/202001/05/2020
603/11/200601/06/2020301/06/201888888888888888888888888888
713/02/200722/05/2020501/12/201810101010101010000001010101010101010101010101010101010
801/03/200701/06/20200115115115115115115115115115115115115115115115115115115115115115115115115115115115115115
909/05/200701/06/20200121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8
1012/03/200701/06/2020201/05/202051515151515151515151515151515151515151515151515151515100
example





Any assistance would be greatly appreciated before I lose any more of my already receding hairline.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Welcome to the MrExcel board!

Just wondering what result you would expect in the green cell for this example, and why?

Also, are the 'empty' cells in columns F, G, H, ... actually empty or do they contain formulas returning ""?

20 06 24.xlsm
BCDEFGHIJKLMNO
5START_DATEEND_DATECONSECEND OF SEQUENCE1/01/20181/02/20181/03/20181/04/20181/05/20181/06/20181/07/20181/08/20181/09/20181/10/2018
111/01/20181/10/201826666
Sheet2 (2)
 
Upvote 0
Hi, very good question! Should that instance occur then I would look to return the most recent time it happened.
 
Upvote 0
for F,G,H they are empty, they are query results from access but will still be treated as a standard blank.
 
Upvote 0
I would consider using some user-defined functions as below. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formulas as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function MaxConsec(rDateHeaders As Range, rValues As Range, rStartDate As Date, rEndDate As Date) As Long
  Dim c As Long, Consec As Long
  
  For c = 1 To rDateHeaders.Columns.Count
    If rDateHeaders(c).Value >= rStartDate And rDateHeaders(c).Value <= rEndDate Then
      If rValues(c).Value = 0 Then
        Consec = Consec + 1
        If Consec > MaxConsec Then MaxConsec = Consec
      Else
        Consec = 0
      End If
    End If
  Next c
End Function

Function LastDate(rDateHeaders As Range, rValues As Range, rStartDate As Date, rEndDate As Date) As Variant
  Dim c As Long, Consec As Long, MaxConsec As Long
  
  LastDate = "N/A"
  For c = 1 To rDateHeaders.Columns.Count
    If rDateHeaders(c).Value >= rStartDate And rDateHeaders(c).Value <= rEndDate Then
      If rValues(c).Value = 0 Then
        Consec = Consec + 1
        If Consec >= MaxConsec Then
          MaxConsec = Consec
          LastDate = rDateHeaders(c).Value
        End If
      Else
        Consec = 0
      End If
    End If
  Next c
End Function

Millixcel 2020-06-25 1.xlsm
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAH
5START_DATEEND_DATECONSECEND OF SEQUENCE1/01/20181/02/20181/03/20181/04/20181/05/20181/06/20181/07/20181/08/20181/09/20181/10/20181/11/20181/12/20181/01/20191/02/20191/03/20191/04/20191/05/20191/06/20191/07/20191/08/20191/09/20191/10/20191/11/20191/12/20191/01/20201/02/20201/03/20201/04/20201/05/2020
63/11/20061/06/202031/06/201888888888888888888888888888
713/02/200722/05/202051/12/201810101010101010000001010101010101010101010101010101010
81/03/20071/06/20200N/A115115115115115115115115115115115115115115115115115115115115115115115115115115115115115
99/05/20071/06/20200N/A121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8121.8
1012/03/20071/06/202021/05/202051515151515151515151515151515151515151515151515151515100
111/03/20181/10/201821/09/20186666
Sheet2 (2)
Cell Formulas
RangeFormula
D6:D11D6=MaxConsec(F$5:AH$5,F6:AH6,B6,C6)
E6:E11E6=LastDate(F$5:AH$5,F6:AH6,B6,C6)
 
Upvote 0
I have one word. Hero!

I've tested this thoroughly and can't find a single issue!

I would have never gotten there in a million years without your help so thank you very much!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,212,932
Messages
6,110,748
Members
448,295
Latest member
Uzair Tahir Khan

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