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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

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