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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Re: Count the period once cycle is completed tricky one

Try something like this UDF :

Code:
Function CycleCount(ColStart As Integer, ColStop As Integer, RowStart As Integer, RowStop As Integer)
    
    Dim RowLp As Integer
    Dim ColLp As Integer
    Dim CyclecountFinal As Integer
    Dim PrevCycleCountVal As Integer
    Dim myVar As String
    
    For ColLp = ColStart To ColStop
        For RowLp = RowStart To RowStop
            myVar = myVar & Cells(RowLp, ColLp) 'Concatenate all of the values together
        Next RowLp
            X = InStr(1, myVar, "X"): One = InStr(1, myVar, "1"): Two = InStr(1, myVar, "2") 'Define First Row containing each string
            myRow = Application.Max(X, One, Two) 'Get Max Row
                If myRow > PrevCycleCountVal Then
                    CyclecountFinal = myRow 'Overwrite value if new column has greater value
                Else
                    'Do Nothing if number is not larger....
                End If
            PrevCycleCountVal = myRow
            myVar = vbNullString
    Next ColLp
    
    CycleCount = CyclecountFinal

End Function

Use it in a worksheet formula like this:

=CycleCount(3,9,6,32) This will yield 27
=CycleCount(3,9,33,62) This will yield 30
=CycleCount(3,9,63,82) This will yield 15
 
Last edited:
Upvote 0
Re: Count the period once cycle is completed tricky one

Try something like this UDF
Hi Matt Mickle, thank you for the function please can you explain may I do not understand how do I identify the period of cycle 1, X & 2 is completed in the all 7 columns.

The results are showing in the column J it is manually calculated I need code to look in the range and find the period of the cycle completed and show the results in the column J as shown


Kind Regards,
Kishan
 
Last edited:
Upvote 0
Re: Count the period once cycle is completed tricky one

You can use a variation of the formula I provided earlier:

ABCDEFGHIJKLMNOPQR
1
2
3
4
5C1C2C3C4C5C6C7Count CycleC1C2C3C4C5C6C7
6X1112XX275611119427
7X2X121130571333076
8X1112XX1515410313157
92111121#N/A4#N/A#N/A#N/A#N/A#N/A
1011111X1#N/A4#N/A#N/A#N/A#N/A#N/A
11XXX1211#N/A4#N/A#N/A#N/A#N/A#N/A
12X11211X

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet17

Worksheet Formulas
CellFormula
K6=IF(ISERROR(MAX(L6:R6)),"",MAX(L6:R6))
L6=MAX(MATCH("X",OFFSET(C$6:C$66,SUM($K$5:$K5),0),0),MATCH(1,OFFSET(C$6:C$66,SUM($K$5:$K5),0),0),MATCH(2,OFFSET(C$6:C$66,SUM($K$5:$K5),0),0))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



Put the L6 formula in, and copy to R6, then down the columns as needed. Put the K6 formula in and drag down as needed. You can hide the M:R columns if you want.
 
Upvote 0
Re: Count the period once cycle is completed tricky one

You can use a variation of the formula I provided earlier:

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
1
2
3
4
5
C1
C2
C3
C4
C5
C6
C7
Count Cycle
C1
C2
C3
C4
C5
C6
C7
6
X
1
1
1
2
X
X
27
5
6
11
11
9
4
27
7
X
2
X
1
2
1
1
30
5
7
13
3
30
7
6
8
X
1
1
1
2
X
X
15
15
4
10
3
13
15
7
9
2
1
1
1
1
2
1
#N/A
4
#N/A
#N/A
#N/A
#N/A
#N/A
10
1
1
1
1
1
X
1
#N/A
4
#N/A
#N/A
#N/A
#N/A
#N/A
11
X
X
X
1
2
1
1
#N/A
4
#N/A
#N/A
#N/A
#N/A
#N/A
12
X
1
1
2
1
1
X

<tbody>
</tbody>
Sheet17


Worksheet Formulas
Cell
Formula
K6
=IF(ISERROR(MAX(L6:R6)),"",MAX(L6:R6))
L6
=MAX(MATCH("X",OFFSET(C$6:C$66,SUM($K$5:$K5),0),0),MATCH(1,OFFSET(C$6:C$66,SUM($K$5:$K5),0),0),MATCH(2,OFFSET(C$6:C$66,SUM($K$5:$K5),0),0))

<tbody>
</tbody>

<tbody>
</tbody>



Put the L6 formula in, and copy to R6, then down the columns as needed. Put the K6 formula in and drag down as needed. You can hide the M:R columns if you want.
Hi Eric, ok I understand thank you for the explanation this scan each row and show the results in the corresponding column period of the cycle has completed that is perfect.

One more question now we know period of cycle results are 27, 30, 15 now...

How can I place 27 in cell J32 = 27 to identify that 1st cycle is finished in the row 32.
And then 30 in the cell J62 = 30 to identify that 2nd cycle is finished in the row 62.
And then 15 in the cell J77 = 15 to identify that 3rd cycle is finished in the row 77.

And so on...

Please is it possible to do

Thank you once again for your help

Kind Regards,
Kishan :)
 
Last edited:
Upvote 0
Re: Count the period once cycle is completed tricky one

Sticking with formulas, put this in J6 and drag down:

=IF(ROWS($J$6:$J6)=SUM(OFFSET($K$6,0,0,COUNT($J$5:$J5)+1)),OFFSET($K$6,COUNT($J$5:$J5),0),"")

A macro can do this too.
 
Upvote 0
Re: Count the period once cycle is completed tricky one

Sticking with formulas, put this in J6 and drag down:

=IF(ROWS($J$6:$J6)=SUM(OFFSET($K$6,0,0,COUNT($J$5:$J5)+1)),OFFSET($K$6,COUNT($J$5:$J5),0),"")

A macro can do this too.
Hi Eric, This is Amazing!! working like a charm. If this could be done by the macro I will prefer please if you could do the macro for me. In this case we do not need the helper columns.
I really do want only the results for periods in column J where in the row cycle is completed.

Thank you

Kind Regards,
Kishan

 
Upvote 0
Re: Count the period once cycle is completed tricky one

If you want to do without the helper columns, put a 0 in C5, then put this charming formula in C6:

=IF(PRODUCT(MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)=1,1,0))*MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)=2,1,0))*MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)="X",1,0))),ROW(J6)-LOOKUP(2,1/($J$1:$J5<>""),ROW($J$1:$J5)),"")

confirmed with Control+Shift+Enter. Then drag down the column. If you still want a macro, I'll take a look at it tomorrow.
 
Upvote 0
Re: Count the period once cycle is completed tricky one

If you want to do without the helper columns, put a 0 in C5, then put this charming formula in C6:

=IF(PRODUCT(MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)=1,1,0))*MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)=2,1,0))*MMULT(TRANSPOSE(ROW((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6))^0),IF((INDEX($C$1:$C$1000,LOOKUP(2,1/($J$1:$J5<>""),ROW($J$2:$J6))):I6)="X",1,0))),ROW(J6)-LOOKUP(2,1/($J$1:$J5<>""),ROW($J$1:$J5)),"")

confirmed with Control+Shift+Enter. Then drag down the column. If you still want a macro, I'll take a look at it tomorrow.
Wow Eric, how you have written such a huge formula it is working as request. :)

I do appreciate your help very much and thanks for spending your precious time.

Please if you could write a macro I would like to have it.

Good Luck

Kind Regards,
Kishan :)

 
Upvote 0
Re: Count the period once cycle is completed tricky one

Hi Eric,

If it is not a much trouble for you kindly could you make a 2 macro one for Post#4 to identify the column & another for post#8 to identify the row please

Thank you for your time.

Kind Regards,
Kishan
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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