BlueAZCoug
New Member
- Joined
- Dec 29, 2014
- Messages
- 4
Hi everyone, I'm new to this site and hoping to get some help on VBA looping. I have a spreadsheet with financial data for several companies (example shown below, except that my real data is much larger, closer to 50 companies). I compute the average of the gross profit for all companies, and if 80% of the companies are within +/-15% of that average, then I'm done. If 80% of the companies are not within 15% of that average, I remove the maximum and minimum gross profit values and start the process over again by computing the average gross margin of the remaining companies (i.e. after taking out the min and max values). It's a very iterative/repetitive process, and with so many companies it's quite time consuming to do it by hand. I figured it would be easier to use VBA looping to whittle down the population until I get to my 80% target. Hopefully that explanation makes sense. I don't want to delete any of the information, so I'm not looking to delete any rows or anything with the code, I just want to exclude those companies from the calculation in some manner. I've never worked with looping in VBA (I'm somewhat of a VBA virgin if you will), but I'm willing to learn and hoping someone can point me in the right direction. Thanks for you time!
[TABLE="class: grid, width: 712, align: center"]
<tbody>[TR]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD]
[/TR]
[TR]
[TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]
[TD="align: center"][/TD]
[TD="colspan: 2"]
[TD="align: center"][/TD]
[TD="colspan: 2"]
[/TR]
[TR]
[TD]
[TD]
[TD]
[TD]
[TD]
[TD="align: center"][/TD]
[TD]
[TD]
[TD="align: center"][/TD]
[TD]
[TD]
[/TR]
[TR]
[TD]
[TD]Company A
[/TD]
[TD]5.5%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
[TD]Company B
[/TD]
[TD]21.1%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]21.1%
[/TD]
[TD]Yes
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
[TD]Company C
[/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]Company D
[/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]Company E
[/TD]
[TD]13.3%
[/TD]
[TD]No
[/TD]
[TD][/TD]
[TD]13.3%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
[TD]Company F
[/TD]
[TD]42.8%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]# of companies within 15% of avg:
[/TD]
[TD][/TD]
[TD] 3
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 3
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]Total # of companies:
[/TD]
[TD][/TD]
[TD] 6
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 4
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]% of population within 15% of avg:
[/TD]
[TD][/TD]
[TD]50%
[/TD]
[TD][/TD]
[TD][/TD]
[TD]75%
[/TD]
[TD][/TD]
[TD][/TD]
[TD]100%
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
[TD]Result of test:
[/TD]
[TD][/TD]
[TD]Fail
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Fail
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Pass
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 712, align: center"]
<tbody>[TR]
[TD]
A
[/TD][TD]
B
[/TD][TD]
C
[/TD][TD]
D
[/TD][TD]
E
[/TD][TD]
F
[/TD][TD]
G
[/TD][TD]
H
[/TD][TD]
I
[/TD][TD]
J
[/TD][TD]
K
[/TD][/TR]
[TR]
[TD]
1
[/TD][TD][/TD]
[TD][/TD]
[TD="colspan: 2"]
Iteration #1
[/TD][TD="align: center"][/TD]
[TD="colspan: 2"]
Iteration #2
[/TD][TD="align: center"][/TD]
[TD="colspan: 2"]
Iteration #3
[/TD][/TR]
[TR]
[TD]
2
[/TD][TD]
Company Name
[/TD][TD]
2013 GM%
[/TD][TD]
Within 15% of Avg?
[/TD][TD]
Exclude?
[/TD][TD="align: center"][/TD]
[TD]
Within 15% of Avg?
[/TD][TD]
Exclude?
[/TD][TD="align: center"][/TD]
[TD]
Within 15% of Avg?
[/TD][TD]
Exclude?
[/TD][/TR]
[TR]
[TD]
3
[/TD][TD]Company A
[/TD]
[TD]5.5%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
4
[/TD][TD]Company B
[/TD]
[TD]21.1%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]21.1%
[/TD]
[TD]Yes
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
5
[/TD][TD]Company C
[/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
6
[/TD][TD]Company D
[/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[TD]20.3%
[/TD]
[TD]Yes
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
7
[/TD][TD]Company E
[/TD]
[TD]13.3%
[/TD]
[TD]No
[/TD]
[TD][/TD]
[TD]13.3%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
8
[/TD][TD]Company F
[/TD]
[TD]42.8%
[/TD]
[TD]No
[/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Exclude
[/TD]
[/TR]
[TR]
[TD]
9
[/TD][TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
10
[/TD][TD]# of companies within 15% of avg:
[/TD]
[TD][/TD]
[TD] 3
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 3
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
11
[/TD][TD]Total # of companies:
[/TD]
[TD][/TD]
[TD] 6
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 4
[/TD]
[TD][/TD]
[TD][/TD]
[TD] 2
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
12
[/TD][TD]% of population within 15% of avg:
[/TD]
[TD][/TD]
[TD]50%
[/TD]
[TD][/TD]
[TD][/TD]
[TD]75%
[/TD]
[TD][/TD]
[TD][/TD]
[TD]100%
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
13
[/TD][TD]Result of test:
[/TD]
[TD][/TD]
[TD]Fail
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Fail
[/TD]
[TD][/TD]
[TD][/TD]
[TD]Pass
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]