Count each character after breakout

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>

Data are in columns C:D I want to count each character 1, X or 2 after each breakout when columns C=1 & D=1 in the same row
</SPAN></SPAN>

For example when in the both columns in the same row find 1 & 1 do count of 1, X, 2 in the column "C" in the columns F:H and of the column "D" in the columns J:K as in the example below row 13 has 1 & 1 so C14:C28 counts are in F13:H28 And D13:D:28 counts are in J14:L28
</SPAN></SPAN>

Example...


Book1
ABCDEFGHIJKLMN
1
2
3
4P1P1P1P2P2P2
5P1P21X21X2
6XX
72X
8X1
9X1
1012
11X1
12X1
1311000000
14X111
15XX21
162X12
172221
182132
192143
202X53
211X14
222X65
232174
24X232
252185
26X146
271223
282X96
2911000000
301X11
3111000000
3211000000
331211
342111
351222
3611000000
372211
38X212
392121
401X11
4111000000
4211000000
432111
442221
45X112
46XX21
47XX32
4811000000
491211
50X111
511222
52X223
53X234
5411000000
551211
562X11
571222
582X22
591X33
602233
612141
622254
6311000000
642211
65XX11
662X22
671X13
682232
69X223
701224
71X235
721236
731X44
742141
751257
7611000000
771X11
782211
791222
80X111
812X22
8211000000
832111
841X11
851221
861X32
87X112
881242
892123
902233
91XX23
921254
931265
942246
95
96
97
98
Sheet1
</SPAN></SPAN>

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


Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG10Mar02
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] oSet [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Q [COLOR="Navy"]As[/COLOR] Variant
[COLOR="Navy"]Dim[/COLOR] Fd  [COLOR="Navy"]As[/COLOR] Boolean
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("C6"), Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] Ac = 0 To 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Offset(, Ac)
   [COLOR="Navy"]If[/COLOR] Cells(Dn.Row, "C") = 1 And Cells(Dn.Row, "D") = 1 [COLOR="Navy"]Then[/COLOR]
       [COLOR="Navy"]If[/COLOR] Ac = 0 And Cells(Dn.Row, "C") = 1 [COLOR="Navy"]Then[/COLOR] Dn.Offset(, 3).Resize(, 3) = 0
       [COLOR="Navy"]If[/COLOR] Ac = 1 And Cells(Dn.Row, "D") = 1 [COLOR="Navy"]Then[/COLOR] Dn.Offset(, 6).Resize(, 3) = 0
       .RemoveAll
     Fd = True
    [COLOR="Navy"]ElseIf[/COLOR] Fd [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]Select[/COLOR] [COLOR="Navy"]Case[/COLOR] Dn.Value
            [COLOR="Navy"]Case[/COLOR] 1: oSet = 3
            [COLOR="Navy"]Case[/COLOR] "X": oSet = 4
            [COLOR="Navy"]Case[/COLOR] 2: oSet = 5
        [COLOR="Navy"]End[/COLOR] Select
        oSet = IIf(Ac = 0, oSet, oSet + 3)
        
        [COLOR="Navy"]If[/COLOR] Not .Exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
           .Add Dn.Value, 1
            Dn.Offset(, oSet).Value = 1
        [COLOR="Navy"]Else[/COLOR]
           Q = .Item(Dn.Value)
           Q = Q + 1
           Dn.Offset(, oSet).Value = Q
        .Item(Dn.Value) = Q
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
Fd = False
[COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG10Mar02
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, n [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] oSet [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] Q [COLOR=navy]As[/COLOR] Variant
[COLOR=navy]Dim[/COLOR] Fd  [COLOR=navy]As[/COLOR] Boolean
[COLOR=navy]Set[/COLOR] Rng = Range(Range("C6"), Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR=navy]For[/COLOR] Ac = 0 To 1
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng.Offset(, Ac)
   [COLOR=navy]If[/COLOR] Cells(Dn.Row, "C") = 1 And Cells(Dn.Row, "D") = 1 [COLOR=navy]Then[/COLOR]
       [COLOR=navy]If[/COLOR] Ac = 0 And Cells(Dn.Row, "C") = 1 [COLOR=navy]Then[/COLOR] Dn.Offset(, 3).Resize(, 3) = 0
       [COLOR=navy]If[/COLOR] Ac = 1 And Cells(Dn.Row, "D") = 1 [COLOR=navy]Then[/COLOR] Dn.Offset(, 6).Resize(, 3) = 0
       .RemoveAll
     Fd = True
    [COLOR=navy]ElseIf[/COLOR] Fd [COLOR=navy]Then[/COLOR]
        [COLOR=navy]Select[/COLOR] [COLOR=navy]Case[/COLOR] Dn.Value
            [COLOR=navy]Case[/COLOR] 1: oSet = 3
            [COLOR=navy]Case[/COLOR] "X": oSet = 4
            [COLOR=navy]Case[/COLOR] 2: oSet = 5
        [COLOR=navy]End[/COLOR] Select
        oSet = IIf(Ac = 0, oSet, oSet + 3)
        
        [COLOR=navy]If[/COLOR] Not .Exists(Dn.Value) [COLOR=navy]Then[/COLOR]
           .Add Dn.Value, 1
            Dn.Offset(, oSet).Value = 1
        [COLOR=navy]Else[/COLOR]
           Q = .Item(Dn.Value)
           Q = Q + 1
           Dn.Offset(, oSet).Value = Q
        .Item(Dn.Value) = Q
    [COLOR=navy]End[/COLOR] If
[COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR]
Fd = False
[COLOR=navy]Next[/COLOR] Ac
[COLOR=navy]End[/COLOR] [COLOR=navy]With[/COLOR]
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Wow! Mick, I liked the VBA solution it is superb working as required </SPAN></SPAN>

Thank you so much for your kind help
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Upvote 0

Forum statistics

Threads
1,224,947
Messages
6,181,952
Members
453,075
Latest member
anandn93

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