Count for each 30 day period starting with the first "x", if there are 4 or more x's in it.

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,168
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I need a count that will tell me in any 30 day period starting with the first "x" if there are 4 or more x's in it. I have approx 60,000 rows of data. Thanks in advance!!!
8/30/20218/31/20219/1/20219/2/20219/3/20219/4/20219/5/20219/6/20219/7/20219/8/20219/9/20219/10/20219/11/20219/12/20219/13/20219/14/20219/15/20219/16/20219/17/20219/18/20219/19/20219/20/20219/21/20219/22/20219/23/20219/24/20219/25/20219/26/20219/27/20219/28/20219/29/20219/30/202110/1/202110/2/202110/3/202110/4/202110/5/202110/6/202110/7/202110/8/202110/9/202110/10/202110/11/202110/12/202110/13/202110/14/202110/15/202110/16/202110/17/202110/18/202110/19/202110/20/202110/21/202110/22/202110/23/202110/24/202110/25/202110/26/202110/27/202110/28/202110/29/202110/30/202110/31/202111/1/202111/2/202111/3/202111/4/2021Count
xxxxxx1



8/30/20218/31/20219/1/20219/2/20219/3/20219/4/20219/5/20219/6/20219/7/20219/8/20219/9/20219/10/20219/11/20219/12/20219/13/20219/14/20219/15/20219/16/20219/17/20219/18/20219/19/20219/20/20219/21/20219/22/20219/23/20219/24/20219/25/20219/26/20219/27/20219/28/20219/29/20219/30/202110/1/202110/2/202110/3/202110/4/202110/5/202110/6/202110/7/202110/8/202110/9/202110/10/202110/11/202110/12/202110/13/202110/14/202110/15/202110/16/202110/17/202110/18/202110/19/202110/20/202110/21/202110/22/202110/23/202110/24/202110/25/202110/26/202110/27/202110/28/202110/29/202110/30/202110/31/202111/1/202111/2/202111/3/202111/4/2021count
xxxxxxxxxxxxx2
 
Last edited by a moderator:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try:
VBA Code:
Sub countx()
    Application.ScreenUpdating = False
    Dim v As Variant, r As Long, c As Long, cnt As Long
    v = Range("A1").CurrentRegion.Value
    For r = 2 To UBound(v)
        For c = 1 To UBound(v, 2)
            If v(r, c) = "x" Then
                If WorksheetFunction.CountA(Cells(r, c).Resize(, 30)) >= 4 Then
                    cnt = cnt + 1
                End If
                Exit For
            End If
        Next c
    Next r
    MsgBox cnt
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
mumps,
First of all thank you so much for responding to my post! It worked for a single line of data but what i need is for 60,000 lines. Please see below.

Count8/30/20218/31/20219/1/20219/2/20219/3/20219/4/20219/5/20219/6/20219/7/20219/8/20219/9/20219/10/20219/11/20219/12/20219/13/20219/14/20219/15/20219/16/20219/17/20219/18/20219/19/20219/20/20219/21/20219/22/20219/23/20219/24/20219/25/20219/26/20219/27/20219/28/20219/29/20219/30/202110/1/202110/2/202110/3/202110/4/202110/5/202110/6/202110/7/202110/8/202110/9/202110/10/202110/11/202110/12/202110/13/202110/14/202110/15/202110/16/202110/17/202110/18/202110/19/202110/20/202110/21/202110/22/202110/23/202110/24/202110/25/202110/26/202110/27/202110/28/202110/29/202110/30/202110/31/202111/1/202111/2/202111/3/202111/4/2021
2xxxxxxxxxx
1xxxxxxxxxxxx
2xxxxxxxxxxxxx
0xxxxx
2xxxxxxxxx
1xxxx
 
Last edited by a moderator:
Upvote 0
What does the "Count" column represent? Are there any blank rows in your data?
 
Upvote 0
Thanks again mumps! The count column represents how many groups of 30 (starting with the first x) has >=4 x's in it. No blank rows.
 
Upvote 0
It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Truancy Formula 30 Day Groups.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBR
1Count8/30/20218/31/20219/1/20219/2/20219/3/20219/4/20219/5/20219/6/20219/7/20219/8/20219/9/20219/10/20219/11/20219/12/20219/13/20219/14/20219/15/20219/16/20219/17/20219/18/20219/19/20219/20/20219/21/20219/22/20219/23/20219/24/20219/25/20219/26/20219/27/20219/28/20219/29/20219/30/202110/1/202110/2/202110/3/202110/4/202110/5/202110/6/202110/7/202110/8/202110/9/202110/10/202110/11/202110/12/202110/13/202110/14/202110/15/202110/16/202110/17/202110/18/202110/19/202110/20/202110/21/202110/22/202110/23/202110/24/202110/25/202110/26/202110/27/202110/28/202110/29/202110/30/202110/31/202111/1/202111/2/202111/3/202111/4/202111/5/202111/6/2021
22xxxxxxxxxx
31xxxxxxxxxxxx
42xxxxxxxxxxxxx
50xxxxx
62xxxxxxxxx
71xxxx
Sheet3 (2)
 
Last edited by a moderator:
Upvote 0
Try:
VBA Code:
Sub countx()
    Application.ScreenUpdating = False
    Dim v As Variant, r As Long, c As Long, cnt As Long, LastRow As Long, lCol As Long, fnd As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column
    For r = 2 To LastRow
        Set fnd = Rows(r).Find("x", LookIn:=xlValues, LookAt:=xlWhole)
        If Not fnd Is Nothing Then
            For c = fnd.Column To lCol Step 30
                If WorksheetFunction.CountA(Cells(r, c).Resize(, 30)) >= 4 Then
                    cnt = cnt + 1
                End If
            Next c
            Range("A" & r) = cnt
        End If
        cnt = 0
    Next r
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
A minor change:
VBA Code:
Sub countx()
    Application.ScreenUpdating = False
    Dim r As Long, c As Long, cnt As Long, LastRow As Long, lCol As Long, fnd As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column
    For r = 2 To LastRow
        Set fnd = Rows(r).Find("x", LookIn:=xlValues, LookAt:=xlWhole)
        If Not fnd Is Nothing Then
            For c = fnd.Column To lCol Step 30
                If WorksheetFunction.CountA(Cells(r, c).Resize(, 30)) >= 4 Then
                    cnt = cnt + 1
                End If
            Next c
            Range("A" & r) = cnt
        End If
        cnt = 0
    Next r
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
mumps, thank you so much! That did the trick. I greatly appreciate all of your help and patience!
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,197
Members
449,214
Latest member
mr_ordinaryboy

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