Count if 3 character "1 X 2" are find in the 3 rows.

Kishan

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

Hi,


Count if 3 character "1 X 2" are find in the 3 rows no matter the if they are not in sequence (I mean can be "1X2", "X12", "2X1" or in any sequence no problem)

Data are in cells C6:I80 (count results in K6:K80

Look "1X2" into 3 rows STARTING FROM C6 for example....

Step1-Start looking in C6, C7, and C8 - D6, D7, and D8 - E6, E7, and E8 - F6, F7, and F8 - G6, G7, and G8 - H6, H7, and H8 - I6, I7, and I8 (DO NOT FOUND "1X2" RESULT = IN K8=0)

Step2-Start looking IN NEXT 3 ROWS C7, C8, and C9 - D7, D8, and D9 - E7, E8, and E9 - F7, F8, and F9 - G7, G8, and G9 - H7, H8, and H9 - I7, I8, and I8 (FOUND "1X2" in - I7, I8, and I8 RESULT = IN K9=1

Step3-Start looking IN NEXT 3 ROWS C8, C9, and C10 - D8, D9, and D10 - E8, E9, and E10 - F8, F9, and F10 - G8, G9, and G10 - H8, H9, and H10 - I8, I9, and I10 (FOUND "1X2" in - C8, C9, and C10 RESULT = IN K10=1

And continue finding into next 3 rows till end and result in column K

Example....


Book1
ABCDEFGHIJKL
1
2
3
4Cycle
5C1C2C3C4C5C6C7Completad
6X111212
7XX21XX1
8X1112120
9211X21X1
101X1X1121
11X2XX2X13
12X1121111
131XX21X11
141112XXX
151XX1111
16X1X212X
1711X121X
1811111X1
19X11XX11
20111121X
211112211
2221X11X1
231111121
24X112112
251111X11
26X111121
2712XXXX1
28111212X
29111221X
30111X111
31111X111
321X11211
332211X1X
341X12111
3521112X1
361XX2112
37X111111
38X211XX1
39X12121X
40111XX12
41XXX11X1
422X21X1X
43XX12X12
44XX1X111
4511X1121
461111X22
472X11111
48121X212
49X1X1212
50X1111X1
51X1X11X2
52X111XX1
53X1122X1
5421X21XX
55XX21X11
561X2X121
57X2X1111
5811X11X1
5911X111X
6021X1112
61X122X11
622111221
631112111
641X21X11
651X1X11X
66XXX1111
67XX22121
681121111
69X111X11
701112X1X
711X1112X
7211X1XXX
731X1X1X2
7411X2211
751XX1X11
761XXXX12
772X1X111
7811X1222
791111X11
80111121X
81
82
Sheet2


Thank you in advance

Regards,
Kishan
 
Hi Eric,

In other words I were observing it can be define first 3 rows display only 2 characters and 4 row close the cycle with 3rd character or I can say with missing one.

Hope this help

Regards,
Kishan
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
The common rule based on your table is that the last character in your sequence can't appear anywhere else in the sequence. Given that, try:

Code:
Sub CheckCycle()
Dim r As Long, c As Long, ctr As Long, x As Boolean

    For r = 9 To Cells(Rows.Count, "C").End(xlUp).Row
        ctr = 0
        For c = 3 To 9
            x = (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), 1) > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), 2) > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), "X") > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(3), Cells(r, c).Value) = 0)
            If x Then ctr = ctr + 1
        Next c
        Cells(r, "K") = ctr
    Next r
    
End Sub
When I run this against the table from post 15, I get your expected answers, except for K11. Based on your latest description, I believe the macro is right, counting D8:D11 and I8:I11.
 
Upvote 0
The common rule based on your table is that the last character in your sequence can't appear anywhere else in the sequence. Given that, try:
Hi Eric,

You have defined very well, this is what I wanted to express but couldn't.


Code:
 Sub CheckCycle()
Dim r As Long, c As Long, ctr As Long, x As Boolean

    For r = 9 To Cells(Rows.Count, "C").End(xlUp).Row
        ctr = 0
        For c = 3 To 9
            x = (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), 1) > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), 2) > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(4), "X") > 0) And _
                (WorksheetFunction.CountIf(Cells(r - 3, c).Resize(3), Cells(r, c).Value) = 0)
            If x Then ctr = ctr + 1
        Next c
        Cells(r, "K") = ctr
    Next r
    
End Sub
Thank you so much for fulfilling my 2nd request this is solved completely perfect.

When I run this against the table from post 15, I get your expected answers, except for K11. Based on your latest description, I believe the macro is right, counting D8:D11 and I8:I11.
Yes you are right answer in the K11 Should be 2, not 1 as I shown in the post#15

I heartily appreciate your kind help

Good Luck

Kind Regards,
Kishan
:)
 
Upvote 0

Forum statistics

Threads
1,215,474
Messages
6,125,024
Members
449,204
Latest member
LKN2GO

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