VBA Code to Copy & Paste Based on Cell Value Then Loop Until Last Row

browncountry

New Member
Joined
Feb 2, 2019
Messages
13
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
[/TD]
[TD="align: center"]A
[/TD]
[TD="align: center"]B
[/TD]
[TD="align: center"]C
[/TD]
[TD="align: center"]D
[/TD]
[TD="align: center"]E
[/TD]
[TD="align: center"]F
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Part Number
[/TD]
[TD]Description
[/TD]
[TD]Qty
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]123
[/TD]
[TD]abc
[/TD]
[TD]3
[/TD]
[TD][/TD]
[TD]123
[/TD]
[TD]abc
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]456
[/TD]
[TD]def
[/TD]
[TD]1
[/TD]
[TD][/TD]
[TD]123
[/TD]
[TD]abc
[/TD]
[/TR]
[TR]
[TD]4
[/TD]
[TD]789
[/TD]
[TD]ghi
[/TD]
[TD]2
[/TD]
[TD][/TD]
[TD]123
[/TD]
[TD]abc
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]456
[/TD]
[TD]def
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]789
[/TD]
[TD]ghi
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]789
[/TD]
[TD]ghi
[/TD]
[/TR]
</tbody>[/TABLE]


I have searched forums and am able to copy and paste a range a certain number of times based on a cell value in VBA, but I cannot seem to get the results I want as shown in the table above. If anyone has time to help, my goal is to select the part number and description and paste it the amount of times the qty column displays and do this until the last part number. My end result is displayed in E2:F7. Thanks in advance!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi & welcome to MrExcel
How about
Code:
Sub browncountry()
   Dim cl As Range
   
   For Each cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
      cl.Resize(, 2).Copy Range("E" & Rows.Count).End(xlUp).Offset(1).Resize(1 * cl.Offset(, 2), 2)
   Next cl
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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