VBA Loop Help Needed

jonchimento

New Member
Joined
Aug 11, 2014
Messages
11
Hello,

I have a series of costs and I want to group them into X dollar groups (In the example below its 300). I have a much larger set of data then shown below and want to create an automated way of doing this because I will have to repeat the process with new data in the future.
I am trying to use VBA loop and am not really getting anywhere.
Hope someone out there can help!

Money (Existing Data)Project (To Be Populated)
1001
2001
2502
502
803
1503
1103
2504
904

<tbody>
</tbody>

Below in my attempt at creating VBA code to do this:


Sub Projects()

x = 300
Range("AX2").Select ActiveCell.FormulaR1C1 = "1"
Do Until Application.SumIf(Range("$B:$B"), 1, Range("$A:$A")) > x
ActiveCell.Offset(1, 0).FormulaR1C1 = "1"
Loop
Do Until Application.SumIf(Range("$B:$B"), 2, Range("$A:$A")) > x
ActiveCell.Offset(1, 0).FormulaR1C1 = "2"
Loop

End Sub
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Welcome to the board.

Does it need to be VBA? If not, and assuming your table begins in A1, try this formula in B2 and copy down:

=INT(SUM($A$2:A2)/301)+1
 
Last edited:
Upvote 0
It worked how I needed, it gave me groups of around my goal number. The groups were below and above the target number with 15% variation, no problem there.
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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