Macro to copy each row multiple times into another sheet

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I'm looking for a macro that can do the following,
I have a sheet called "Product Data"
The headers are in Row 3 so the data starts at row 4
The data range is A4:Z (last row)
Now each row is a different product,
in Column H "Number of Colours" is a number, it can be any number from one up (If cell is blank assume 1)
what I would like is a macro that when run
goes through each Row checks the Number in Column H for that row and makes that many copies into Sheet "Colours" Column A and first empty row,

So If I was writing this in English it would read something like this


For each row in sheet "Product Data" range A4:Zand last row
take the number from column H and copy Row, and paste it that many times in Sheet "Colours" Column A and first empty row,

Please help if you can,
Thanks
Tony
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Macro code
VBA Code:
Sub Macro2()
Dim A
Dim LR As Long, T As Long

LR = Sheets("Product Data").Range("A" & Rows.Count).End(xlUp).Row
A = Sheets("Product Data").Range("A3:Z" & LR)
With Sheets("Colors")
.Range("A1:Z1") = Application.Index(A, 1, 0)
.Range("A1").CurrentRegion.Offset(1, 0).Clear
For T = 2 To UBound(A, 1)
.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(A(T, 8) + 1, 26).Value = Application.Index(A, T, 0)
Next T
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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