Count the period once cycle is completed

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Hi,

This query is bit complicated I will try my best to explain it

Data are located in cells C6:I82 what I need to check cycle for 1, X & 2 among the 7 columns C through I one by one and count the max numbers where the cycle is completed within the 7 column and the count result show in column J

For example...

1st cycle of 1, X, 2 has been completed with in 27 periods in column I so far result in Cell I32 = 27

2nd cycle of 1, X, 2 has been completed with in 30 periods in column G so far result in Cell J62 = 30

And continue finding...

Column K shows only the summary of cycle counts.

Colours are filled just to shown to show example bit clearer.

Example data...


Book1
ABCDEFGHIJKL
1
2
3
4Summary
5C1C2C3C4C5C6C7Count Cycle
6X1112XX27
7X2X121130
8X1112XX15
92111121
1011111X1
11XXX1211
12X11211X
131XX112X
1411X1XXX
151X11X1X
16XX2XX1X
171X1111X
1811X1121
19X11112X
20111X12X
21111X12X
222XX1121
23112121X
24X1111X1
251111111
26X121XXX
271XX2111
28112XXX1
291111X1X
30111X111
311111111
32111XXX227
33211212X
34111111X
3521XXX1X
361X1X112
37X11112X
38X1X1121
39X21XXX1
40111X12X
41XXX1111
4222111X2
43X111112
44X111X11
451X21111
46112111X
47211X11X
481111111
49XX11X22
50X1X1111
51XXXX1X1
52X1X1112
53X1X111X
542XXX1X2
55X212112
561222XX2
57XX1112X
581XX1XX1
591X11111
602X111X1
61X21X111
62212122130
6311111X1
6412121X1
65111X111
66XX11111
67X22X112
681211X11
69X11211X
7011111XX
711121XX1
721XX1112
7311X2X11
741X11X11
751X11211
761X11112
77211112215
781X211XX
79111111X
8011111X1
81222X1XX
822X112X1
83
84
85
86
Sheet1


Thank you in advance

Kishan
 
Try adding the lines in red:

Rich (BB code):
Sub GetCounts()
Dim counts(1 To 3, 1 To 7) As Long, r As Long, ctr As Long, r2 As Long, Cx(1 To 1, 1 To 7) As Long


    Application.ScreenUpdating = False
    
    Range("C:I").Interior.ColorIndex = xlNone
    Range("J:R").ClearContents
    Range("K5:R5") = Array("Count Cycle", "C1", "C2", "C3", "C4", "C5", "C6", "C7")
    r = 6
    ctr = 0
    r2 = 6
    Erase counts, Cx
    While Cells(r, "C") <> ""
        ctr = ctr + 1
        For i = 1 To 7
            If Cells(r, i + 2) = 1 Then counts(1, i) = 1
            If Cells(r, i + 2) = 2 Then counts(2, i) = 1
            If Cells(r, i + 2) = "X" Then counts(3, i) = 1
            If Cx(1, i) = 0 And counts(1, i) * counts(2, i) * counts(3, i) > 0 Then Cx(1, i) = ctr
        Next i
        If WorksheetFunction.Product(counts) > 0 Then
            Cells(r, "J") = ctr
            Cells(r2, "K") = ctr
            Range(Cells(r2, "L"), Cells(r2, "R")).Value = Cx
            r2 = r2 + 1
            ctr = 0
            Erase counts, Cx
        End If
        r = r + 1
    Wend
    
    r = 6
    r2 = 6
    While Cells(r, "K") <> ""
        For i = 1 To 7
            Cells(r2, i + 2).Resize(Cells(r, i + 11)).Interior.Color = vbYellow
        Next i
        r2 = r2 + Cells(r, "K").Value
        r = r + 1
    Wend

    Application.ScreenUpdating = True
    
End Sub
You've been very helpful Eric W, :pray: thank you for adding a colour option, which help a lot distinguish the cycle zone very clearly

I thank you from the bottom of my heart.

Have a nice time good luck

Kind Regards,
Kishan :)
 
Last edited:
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,966
Messages
6,175,661
Members
452,666
Latest member
AllexDee

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