Separate counts depending on start patterns

Kishan

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

Hi,</SPAN></SPAN>

Note: Fill colours not required, it is just to shown to explain the example clearer</SPAN></SPAN>

I want a Formula or batter will be the VBA solution to " Separate counts depending on start patterns ", data in column C:D, count result in columns L:Q & in the S:X</SPAN></SPAN>

Count examples of the row 6, starting C6 has 1|X, so count instance and put them in cell L6 = 2 (Not in the S6), then look count for reverse match pattern X|1=1 put them in cell M6 =1 (not in the T6) then E3= 1|2 put them in N6 (Not in the V6)</SPAN></SPAN>

So the count must be as per left to right order and match put in to L:Q & S:X as per order too. </SPAN></SPAN>

Result data example</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
3
4
5P1P2P3P4P5P6P71|XX|11|22|1X|22|XX|11|X2|11|22|XX|2
61|XX|11|21|12|21|X1|1211
7X|1X|1X|11|X1|11|XX|142
81|X1|22|1X|11|X1|22|12122
92|X1|11|2X|XX|11|12|11111
101|X2|22|1X|X2|2X|X1|111
111|X1|1X|X2|2X|X1|1X|X1
12X|XX|11|11|X1|X2|12|X1121
131|XX|12|12|11|12|X2|X1122
14X|2X|11|X1|11|1X|11|X122
151|11|11|1X|XX|11|12|X11
161|21|2X|11|2X|21|11|X3111
171|XX|11|2X|X1|X1|1X|1221
181|11|X1|11|1X|11|11|111
19X|12|X1|11|2X|11|2X|X221
201|11|X1|XX|1X|11|11|122
211|11|11|XX|21|11|11|2111
221|11|11|11|11|12|XX|111
231|22|11|11|11|11|X1|1111
241|1X|11|11|11|11|12|111
25X|XX|11|1X|11|2X|11|131
26X|21|12|11|11|1X|X1|X111
271|X2|21|11|2X|X1|11|X21
282|1X|X1|1X|X1|X1|11|111
29X|12|12|XX|11|2X|11|23121
30X|1X|X1|11|11|11|X1|111
31
32
Sheet7


Thank you in advance</SPAN></SPAN>

Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
In L6
=COUNTIF($C6:$I6,L$5)
then copy across & down
 
Upvote 0
In L6
=COUNTIF($C6:$I6,L$5)
then copy across & down
Hi Fluff, it is a general formula that does not look the order see the result are not exactly what I want.</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
3
4
5P1P2P3P4P5P6P71|XX|11|22|1X|22|XX|11|X2|11|22|XX|2
61|XX|11|21|12|21|X1|1211121
7X|1X|1X|11|X1|11|XX|12442
81|X1|22|1X|11|X1|22|121221222
92|X1|11|2X|XX|11|12|111111111
101|X2|22|1X|X2|2X|X1|11111
111|X1|1X|X2|2X|X1|1X|X11
12X|XX|11|11|X1|X2|12|X21111211
131|XX|12|12|11|12|X2|X11221122
14X|2X|11|X1|11|1X|11|X221221
151|11|11|1X|XX|11|12|X1111
161|21|2X|11|2X|21|11|X11311131
171|XX|11|2X|X1|X1|1X|1221221
181|11|X1|11|1X|11|11|11111
19X|12|X1|11|2X|11|2X|X221221
201|11|X1|XX|1X|11|11|12222
211|11|11|XX|21|11|11|2111111
221|11|11|11|11|12|XX|11111
231|22|11|11|11|11|X1|1111111
241|1X|11|11|11|11|12|11111
25X|XX|11|1X|11|2X|11|13131
26X|21|12|11|11|1X|X1|X111111
271|X2|21|11|2X|X1|11|X2121
282|1X|X1|1X|X1|X1|11|11111
29X|12|12|XX|11|2X|11|232113121
30X|1X|X1|11|11|11|X1|11111
31
32
Sheet7-1


These count are bit tricky, I have separated them in 2 groups one in the column L:Q & other in the column S:X, here I give you an example of pattern in cells L5: L6 are 1|X, X|1 and in the cells S5:T5 are in reverse order X|1, 1|X, so far count trick is if starting of the row it is 1|X than count will go in L:M, or if starting of the row it is X|1 than count will go in S:T that is why row 6 count in L6:M6 and Row 7 count are in S6:T6</SPAN></SPAN>

Hope this helps</SPAN></SPAN>

Thank you</SPAN></SPAN>


Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
 
Last edited:
Upvote 0
I had not fully understood your requirement and unfortunately, cannot figure out how to do it.
 
Upvote 0
These count are bit tricky, I have separated them in 2 groups one in the column L:Q & other in the column S:X, here I give you an example of pattern in cells L5: L6 are 1|X, X|1 and in the cells S5:T5 are in reverse order X|1, 1|X, so far count trick is if starting of the row it is 1|X than count will go in L:M, or if starting of the row it is X|1 than count will go in S:T that is why row 6 count in L6:M6 and Row 7 count are in S6:T6
I am having trouble deciphering your count requirement. Can you explain why the counts for Rows 12, 26, 28 are in the columns they are in?
 
Upvote 0
I had not fully understood your requirement and unfortunately, cannot figure out how to do it.
Hi Fluff, in the data column C:I, there are total 9 unique patterns, we can put them in 4 different groups as shown below </SPAN></SPAN>
Group1 - 1|1, X|X, 2,2
</SPAN></SPAN>
Group2 -
1|X, X|1</SPAN></SPAN>
Group3 -
1|2, 2|1
</SPAN></SPAN>Group4 - X|2, 2|X </SPAN></SPAN>

Group1 - has only one order, whereever the can appear in the row there is no reverse match. It will look always like the same 1|1, X|X, 2|2 the can not be reversed
</SPAN></SPAN>

Group2- can be appear in the row as it original order first
1|X and after X|1, or May it can come first X|1 and after 1|X</SPAN></SPAN></SPAN>

Group3- can be appear in the row as it original order first
1|2 and after 2|1, or May it can come first 2|1 and after 1|2</SPAN></SPAN></SPAN>

Group4- can be appear in the row as it original order first
X|2 and after 2|X, or May it can come first 2|X and after X|2</SPAN></SPAN>
So what I did
group 2, 3 & 4 I have distributed in 2 groups1st-in the original order and 2nd-in their reverse order as they can be appeared </SPAN></SPAN>

Original order - 1|X, X|1, 1|2, 2|1, X|2, 2|X------ Reverse order - X|1, 1|X, 2|1, 1|2, X|2, 2|X</SPAN></SPAN>

If the row 6 has following patterns Post#1
</SPAN></SPAN>
1|X</SPAN>
X|1</SPAN>
1|2</SPAN>
1|1</SPAN>
2|2</SPAN>
1|X</SPAN>
1|1</SPAN>

<TBODY>
</TBODY>
In this above line 1|X is appeared in the starting first and followed by X|1 so count will go in the group Original order 1|X = 2 (in the cell L6) and X|1=1 (in the cell M6)</SPAN></SPAN>

If the row 7 has following patterns Post#1
</SPAN></SPAN>
X|1</SPAN>
X|1</SPAN>
X|1</SPAN>
1|X</SPAN>
1|1</SPAN>
1|X</SPAN>
X|1</SPAN>

<TBODY>
</TBODY>
In this above line X|1 is appeared in the starting first and followed by 1|X so count will go in the group Reverse order X|1 = 4 (in the cell S6) and 1|X=2 (in the cell T6)</SPAN></SPAN>

The same method will be applied for the rest rows
</SPAN></SPAN>
Hope this helps
</SPAN></SPAN>

Thank you
</SPAN></SPAN>


Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
 
Upvote 0
I am having trouble deciphering your count requirement. Can you explain why the counts for Rows 12, 26, 28 are in the columns they are in?
Hi Rick Rothstein, I think I have wrong placed in the row 12, but the row 26 & 28 seem to be ok</SPAN></SPAN>

Post#1 as shown</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
3
4
5P1P2P3P4P5P6P71|XX|11|22|1X|22|XX|11|X2|11|22|XX|2
12X|XX|11|11|X1|X2|12|X1121
26X|21|12|11|11|1X|X1|X111
282|1X|X1|1X|X1|X1|11|111
31
32
Sheet7


It should be as below</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
3
4
5P1P2P3P4P5P6P71|XX|11|22|1X|22|XX|11|X2|11|22|XX|2
12X|XX|11|11|X1|X2|12|X1211
26X|21|12|11|11|1X|X1|X111
282|1X|X1|1X|X1|X1|11|111
31
32
Sheet7-2


Hope this helps</SPAN></SPAN>

Thank you</SPAN></SPAN>

Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
 
Last edited:
Upvote 0
Hi Rick Rothstein, I think I have wrong placed in the row 12, but the row 26 & 28 seem to be ok
I think I may be starting to understand what you want. Your answer to the following question will tell me if I am right or not. For your example, is the green count in the wrong group for Row 13?
 
Upvote 0
I think I may be starting to understand what you want. Your answer to the following question will tell me if I am right or not. For your example, is the green count in the wrong group for Row 13?
Hi Rick Rothstein, yes I am sorry, Row 13 green count are placed in the wrong group, count should be in other group in the cell U13, but they are placed wrongly in the wrong group in the cell O13</SPAN></SPAN>

Thank you for observing it minutely
</SPAN></SPAN>

Regards,
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Last edited:
Upvote 0
Maybe...


A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
1
2
3
4
5
P1​
P2​
P3​
P4​
P5​
P6​
P7​
1|X​
X|1​
1|2​
2|1​
X|2​
2|X​
X|1​
1|X​
2|1​
1|2​
2|X​
X|2​
6
1|X​
X|1​
1|2​
1|1​
2|2​
1|X​
1|1​
2​
1​
1​
7
X|1​
X|1​
X|1​
1|X​
1|1​
1|X​
X|1​
4​
2​
8
1|X​
1|2​
2|1​
X|1​
1|X​
1|2​
2|1​
2​
1​
2​
2​
9
2|X​
1|1​
1|2​
X|X​
X|1​
1|1​
2|1​
1​
1​
1​
1​
10
1|X​
2|2​
2|1​
X|X​
2|2​
X|X​
1|1​
1​
1​
11
1|X​
1|1​
X|X​
2|2​
X|X​
1|1​
X|X​
1​
12
X|X​
X|1​
1|1​
1|X​
1|X​
2|1​
2|X​
1​
2​
1​
1​
13
1|X​
X|1​
2|1​
2|1​
1|1​
2|X​
2|X​
1​
1​
2​
2​
14
X|2​
X|1​
1|X​
1|1​
1|1​
X|1​
1|X​
1​
2​
2​
15
1|1​
1|1​
1|1​
X|X​
X|1​
1|1​
2|X​
1​
1​
16
1|2​
1|2​
X|1​
1|2​
X|2​
1|1​
1|X​
3​
1​
1​
1​
17
1|X​
X|1​
1|2​
X|X​
1|X​
1|1​
X|1​
2​
2​
1​
18
1|1​
1|X​
1|1​
1|1​
X|1​
1|1​
1|1​
1​
1​
19
X|1​
2|X​
1|1​
1|2​
X|1​
1|2​
X|X​
2​
2​
1​
20
1|1​
1|X​
1|X​
X|1​
X|1​
1|1​
1|1​
2​
2​
21
1|1​
1|1​
1|X​
X|2​
1|1​
1|1​
1|2​
1​
1​
1​
22
1|1​
1|1​
1|1​
1|1​
1|1​
2|X​
X|1​
1​
1​
23
1|2​
2|1​
1|1​
1|1​
1|1​
1|X​
1|1​
1​
1​
1​
24
1|1​
X|1​
1|1​
1|1​
1|1​
1|1​
2|1​
1​
1​
25
X|X​
X|1​
1|1​
X|1​
1|2​
X|1​
1|1​
1​
3​
26
X|2​
1|1​
2|1​
1|1​
1|1​
X|X​
1|X​
1​
1​
1​
27
1|X​
2|2​
1|1​
1|2​
X|X​
1|1​
1|X​
2​
1​
28
2|1​
X|X​
1|1​
X|X​
1|X​
1|1​
1|1​
1​
1​
29
X|1​
2|1​
2|X​
X|1​
1|2​
X|1​
1|2​
3​
1​
2​
1​
30
X|1​
X|X​
1|1​
1|1​
1|1​
1|X​
1|1​
1​
1​
31

<tbody>
</tbody>


Formula in L6 copied across until Q6 and down
=IF(COUNTIF($C6:$I6,L$5),IF(MOD(COLUMN(L6),2)=0,IF(MATCH(L$5,$C6:$I6,0)>IFERROR(MATCH(RIGHT(L$5)&"|"&LEFT(L$5),$C6:$I6,0),100),"",COUNTIF($C6:$I6,L$5)),IF(AND(COUNTIF($C6:$I6,L$5),K6<>""),COUNTIF($C6:$I6,L$5),"")),"")

Formula in S6 copied across until X6 and down
=IF(AND(COUNTIF($C6:$I6,S$5),INDEX($L6:$Q6,MATCH(S$5,$L$5:$Q$5,0))=""),COUNTIF($C6:$I6,S$5),"")

Hope this helps

M.
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,978
Members
449,200
Latest member
Jamil ahmed

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