Very complex Loop

L

LuisE

I need to loop thru “B1:B100†to place a number in each cell in that range
following this criterion: in “A1:A100â€, every time the value changes, I need
to count the total occurrences of that value and divide 1 by that number (of
occurrences) then place that result in each correspondent cell in column B
then move to the next unique value and do the same. Obviously the data in
column A is sorted in order to avoid duplicates.


Thanks in advance
 
M

Mike H

Hi,

If i've understood correctly this does what you want. Right click your sheet
tab, view code and paste this in and run it

Sub human()
Set myrange = Range("A2:A100")
For Each c In myrange
Count = Count + 1
If c.Value <> c.Offset(-1, 0).Value Then
c.Offset(-1, 1).Value = 1 / Count
Count = 0
End If
Next
End Sub

Mike
 

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