Hi All,
I'm looking for help for a formula that sums column "A" that is populated with numbers, and puts a total of 24 from that column into columns b, c, d...etc until all have been allocated.
Thanks in advance
Michael
Hi All,
I'm looking for help for a formula that sums column "A" that is populated with numbers, and puts a total of 24 from that column into columns b, c, d...etc until all have been allocated.
Thanks in advance
Michael
No, sorry. I don't follow your explanation. You will have to mock up a sample Excel sheet.
Make sure there is enough data to demonstrate your need. Make sure your desired results are shown, mock them up manually if necessary. Remember to remove ALL confidential information first!!!
Click on GO ADVANCED and use the paperclip icon to open the upload window.
The paperclip icon
Glenn
None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU
Can you please post a small sample file showing the expected results.
Click "Go Advanced" the Paper Clip icon: "Add Files", "Browse", "Upload", "Done"
Thanks for replies,
I do have a sheet on what I've been doing, plus a desired end result, which is on the second tab.
Thanks
Hi,
Just wondering has anyone had any luck with this? I've hunted all over google and couldn't find anything.
You mean something like: copypaste in a2:
![]()
=IF(OR(G2="";H2="";I2="";J2="";K2="";L2="";M2="";N2="";O2="";P2="";R2="";Q2="";S2="";T2="");24;SUM(G2:T2))
Thanks yumpup,
That doesn't seem to work? Not sure if I have missed something with that formula. The result I am looking for is the formula would look down column F sum to 24 then copy those numbers from column F into column G, then continue to sum to 24 again and copy those from column F into column H, etc.
The attached is a VBA solution.
Data in Sheet "Pallets" must preferably be sorted in Descending order of Column F BUT it will work with F unsorted.
I have added data into F just for testing purposes.
Ranges within the macro may need to be changed (no doubt) to match your real data although I have tried to make everything dynamic.
Click RUN to execute macro
![]()
Sub Allocate_Pallets() Dim LastRow As Long Dim LastCol As Long Dim InRng As Range Dim OutRng As Range Dim InArray As Variant Dim OutArray() As Long Dim r As Long Dim c As Long Dim rr As Long Dim cc As Long Dim ncol As Long Dim PSum() As Long Const pSize As Integer = 24 Dim ws1 As Worksheet Application.ScreenUpdating = False Set ws1 = Worksheets("Pallets") ws1.Activate With ActiveSheet LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column End With Set InRng = ws1.Range("F2:F" & LastRow) Set OutRng = ws1.Range(Cells(2, 7), Cells(LastRow, LastCol - 3)) ncol = Round(Range("F" & LastRow + 1) / pSize, 1) ReDim PSum(LastRow) ReDim OutArray(LastRow, ncol + 2) ' ' Read data into array ' InArray = InRng ' ' Clear output range ' OutRng.ClearContents cc = -1 Finished = False ' ' Loop through input array ' lastnz = LastRow - 1 ' ' Allocate all full pallets initially ' For r = 1 To UBound(InArray, 1) For c = 1 To UBound(InArray, 2) If InArray(r, c) > 0 Then Do While InArray(r, c) >= pSize cc = cc + 1 OutArray(r - 1, cc) = pSize PSum(cc) = PSum(cc) + OutArray(r, cc) InArray(r, c) = InArray(r, c) - pSize Loop End If Next c Next r ' ' Allocate remainder to pallets ' cc = cc + 1 For r = 1 To UBound(InArray, 1) For c = 1 To UBound(InArray, 2) finish = True ix = 1 ' ' find "ix" th largest value ' pValue = WorksheetFunction.Large(InArray, ix) ' ' Loop adding to pallets to maximum (or nearest value) ' Do While PSum(cc) < 24 And pValue > 0 finish = False r = WorksheetFunction.Match(pValue, InArray, 0) ' ' Check we will not exceed pallet limit ' If PSum(cc) + pValue <= 24 Then OutArray(r - 1, cc) = pValue PSum(cc) = PSum(cc) + pValue InArray(r, c) = InArray(r, c) - pValue ' Else ix = ix + 1 ' End If pValue = WorksheetFunction.Large(InArray, ix) Loop ' ' move to next load ' cc = cc + 1 Next c If finishtrue Then GoTo outp: Next r outp: ' ' Output results .... ' OutRng = OutArray ' 'Sum pallets ' For cc = 1 To ncol + 2 c = cc + 5 Cells(LastRow + 1, c) = Application.Sum(Range(Cells(2, c), Cells(LastRow, c))) Next cc Application.ScreenUpdating = True End Sub
Last edited by JohnTopley; 11-08-2015 at 05:35 PM.
Hi John,
Thanks very much for your solution. I have had a play around with the sheet and works great.
The only exception is that I have not written any VBA and is out of my league.
While having a look play with the sheet all these #N/A's appeared and I am clueless on how to fix.
I have reattached the file, are you able to have another look at it?
Thanks for your time
Michael
Hi,
See attached for updates to macro.
I discovered other "problems" doing further testing while addressing your query so I'm hoping all are cleared now.
John
Last edited by JohnTopley; 11-09-2015 at 08:55 AM.
Hi John
Thanks for looking over again, but the attachment appears to be invalid??
Michael
Sorry John,
Doesn't seem to be updating. I have changed some crate amounts, then clicked run, nothing happened. Macros have been enabled, just wondering if im missing something?
Michael
tried once again, worked this time
I can Open/Download O.K.
What error message do you get?
If you are updating "Crate Amounts" then check formulae in E and F.
I simply typed data into F so "destroyed" any formula you had in that column.
I added the formula (=ROUNDUP(E2,0)) at this end and worked OK.
Thanks John,
This is working perfectly, I appreciate your help.
Michael
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks