Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Very complex Loop

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Very complex Loop

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

"LuisE" wrote:

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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Very complex Loop

Thanks Sandy.

Let's say that in the range the enrty "Florida" is repeated 4 times, then I
want to put 0.25 in each coreesponding cell in column B, 0.333 if it was
repeated only 3 times.



"Sandy Mann" wrote:

What do you mean by

to count the total occurrences of that value

and then I assume that you want the reciprocal of that number of
occurrences?


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"LuisE" wrote in message
...
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







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,345
Default Very complex Loop

You don't need VBA to do that, you can do it with formulas:

=IF(A1="","",1/(COUNTIF($A$1:$A$100,A1)))

In B1 and dragged down on the fill handle will do it.

If you are *never* going to have any blank cells then you only need:

=1/(COUNTIF($A$1:$A$100,A1))

--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"LuisE" wrote in message
...
Thanks Sandy.

Let's say that in the range the enrty "Florida" is repeated 4 times, then
I
want to put 0.25 in each coreesponding cell in column B, 0.333 if it was
repeated only 3 times.



"Sandy Mann" wrote:

What do you mean by

to count the total occurrences of that value

and then I assume that you want the reciprocal of that number of
occurrences?


--
HTH

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk


"LuisE" wrote in message
...
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










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
complex color fill conditions- if statements or complex formula? lilly8008 Excel Discussion (Misc queries) 1 December 18th 09 04:57 AM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Complex Index Match Help (or at least complex to me) Jennifer Reitman Excel Discussion (Misc queries) 3 August 10th 06 08:51 PM
Loop for a Complex Formula monir Excel Programming 3 March 26th 05 07:37 PM
Do---Loop Error in Complex Code Pete T[_2_] Excel Programming 5 October 14th 03 06:54 PM


All times are GMT +1. The time now is 10:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"