Macro to copy an x number of times

bmrsalgas

New Member
Joined
Aug 11, 2017
Messages
26
I want to check on a sheet reference number and the amount of times that this reference number repeats it self on the datam (img01)

And after checking this copy the reference number and paste the x number of times that it repeats (img02)

Can anyone help me with this?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
bmrsalgas,

As long as there are no duplicates in Column AB, then this will loop through each quantity in AC and correctly out put data in AG:AH. Let me know if this is what you needed.

Code:
Sub Test()

    For Each cell In ActiveSheet.Range("AC2:AC" & Range("AC" & Rows.Count).End(xlUp).Row)
        With ActiveSheet
            Reference = .Range("AB" & cell.Row).Value
            Quantity = .Range("AC" & cell.Row).Value
            
                For i = 1 To Quantity
                    LR = Range("AG" & Rows.Count).End(xlUp).Row
                    
                    .Range("AG" & LR + 1).Value = Reference
                    .Range("AH" & LR + 1).Value = Quantity
                Next
        End With
    Next cell
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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