Creating code to count the matching records in each column

Brew

Well-known Member
Joined
Sep 29, 2003
Messages
1,569
How do I create code for the range DW63:EW116 that will record in each column the count of row(s) that letter “O” between each “H”. Always restart the count with the first “O” match after the “H”. Paste the result in the same cell as the match.
Partial Example:

If DW63:DW85 =, THEN THE UPDATE RESULT SHOULD BE
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,4
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,5
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,6
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1
O,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2
H,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,H
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi

Will a formula do???

Code:
=IF(DW63="H","H",IF(AND(DW63="O",DX62="H"),1,DX62+1))


Assumes the formula is in DX63

Copy down as required.


Tony
 
Upvote 0
No I need the code, in order the analyze the data before and after execution of the function
 
Upvote 0
HI

What is in columns DX:EW and what column is receiving the output???


Tony
 
Upvote 0
I need to change the source range over one column to DX63:EX116. Each column within that range only has either a letter "H" or letter "O" in each cell and the output should replace the original data in the source range. So the output range is the DX63:EX116.
 
Upvote 0
Hi

So in the range DX63:EX116 you are leaving the H alone, and replacing the O with the count???

Does each column always start with an "H"?

Or if you have O in rows 115, 116 of one column and 63 of the next column, then the O in row 63 is replaced by the next incremental number???


Tony
 
Upvote 0
So in the range DX63:EX116 you are leaving the H alone, and replacing the O with the count???
Yes

Does each column always start with an "H"?
No, it can be either H or O.

Or if you have O in rows 115, 116 of one column and 63 of the next column, then the O in row 63 is replaced by the next incremental number???
Im not sure I follow this question, but, each column's records are independent of another column, so not counts are carried over to another column.
 
Upvote 0
Ahhh!, i think I understand the 3rd question,
if row 114 is H, 115 =O and 116 =O and then the next column, row 63=O, then the result should be the following:

114=H
115=1
116=2
next col
63=1
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,791
Members
449,188
Latest member
Hoffk036

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