Find Match and count order

D

dkenebre

How do I automate the following example with code:
Sample data
DX63:EX63 H,O,O,O,H,H,O,O,O,O,O,O,O,O,O,O,H,O,O,O,H,O,O,O,O,H,O
DX64:DX64 H,O,O,O,H,O,O,O,H,O,O,O,O,O,O,H,O,O,O,O,H,O,O,O,O,H,H
Result
GE63:GJ63 = 1, 5, 6, 17, 21, 26
GE64:GK64 = 1, 5, 9, 16, 21, 26, 27

Apply for each source data row within the range DX63:EX116,
and place the output for each row in the range GE63:GM116
Record the order of each “H” within the range of each row of the sourc
range
 
T

Toppers

Hi,
Try this. I got slightly confused as whether data was only in column
DX or both DX and EX. This loops through DX but you modify to add EX.

Sub FindHpos()
For i = 63 To 116
col = 187 ' GE
srchstring = Replace(Range("DX" & i), ",", "") ' Remove ,
Do While InStr(1, srchstring, "H") <> 0
n = InStr(1, srchstring, "H") ' position of H
Cells(i, col) = n
col = col + 1
srchstring = Replace(srchstring, "H", "X", 1, 1) ' replace next H
with X
Loop
Next i
End Sub

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top