Repeat rows / split value

shippey121

Well-known Member
Joined
Mar 21, 2006
Messages
1,003
Good Morning All

i have a data set that shows total copies that i need to split into Box sizes to create labels each box can hold 60 copies
this data can be inserted into this list or a complete new blank sheet,

ive seen lots of code that can repeat rows x times which i could use then manually change the values but i have over 1000 rows of data that will end up be 1000s after being split into boxes

so the table below
row 2 would be repeated 3 times 2 x 60 , 1 x 20
row 3 would remain as 1
row 4 would remain as 1
row 5 would be repeated 5 times 5 x 60

the data set is A to F so an additonal column could be added to show the box quantity

anyone any ideas would be much appreciated...thanks Craig
FINAL QuantityCoverInners
140Maths Year 110mm Square
60Maths Year 210mm Square
5Maths Year 310mm Square
300Maths Year 410mm Square
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
VBA Code:
Option Explicit
Sub split()
Dim lr&, i&, k&, remain&, qty&, rng, arr(1 To 1000000, 1 To 3)
lr = Cells(Rows.Count, "A").End(xlUp).Row
rng = Range("A2:C" & lr).Value
    For i = 1 To lr - 1
        If rng(i, 1) <= 60 Then
            k = k + 1
            arr(k, 1) = rng(i, 1): arr(k, 2) = rng(i, 2): arr(k, 3) = rng(i, 3)
        Else
            remain = rng(i, 1)
            Do While remain > 0
                k = k + 1
                qty = WorksheetFunction.Min(remain, 60)
                arr(k, 1) = qty: arr(k, 2) = rng(i, 2): arr(k, 3) = rng(i, 3)
                remain = remain - qty
            Loop
        End If
    Next
Range("A2").Resize(k, 3).Value = arr
End Sub
before.PNG
after.PNG
 
Upvote 0
Solution
well that my friend is genius..thank you..this has just saved me hours
i modifyied it slightly as may range of data is A to F but worked that out
i was thinking of running code to duplicate all lines first and then after that tackle the amounts

cheers Craig
 
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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