Macro to repeat copy paste until empty cell

sbeedle

New Member
Joined
Sep 11, 2017
Messages
5
I am hoping someone might be able to help me create a macro that copy and pastes data from two sources. I have a store list and a sku list. Each store will need to be married to the sku list in a column. For instance, store number 3 gets copy and pasted in front of each sku in the list. The sku list is then duplicated under the first and the next store number is copy and pasted in front of that list. This would continue until the end of the store list. I have attached screen shot to hopefully help explain. Column A is store list, C and D the sku list/description, columns F-H the result that I would like to see. The result in the screen shot is only for the first 2 stores and I would like to have it run the whole list of stores. This is just a small portion of the data I am looking to do this with - I am just showing a small example to apply to the larger actual project. Thank you in advance for any help you may be able to provide!!

Scott

Data Example.JPG
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
How about
VBA Code:
Sub sbeedle()
   Dim Rng As Range, Cl As Range
   Dim i As Long
   i = 3
   Set Rng = Range("C3:D" & Range("C" & Rows.Count).End(xlUp).Row)
   For Each Cl In Range("A3", Range("A" & Rows.Count).End(xlUp))
      Cl.Copy Range("F" & i).Resize(Rng.Rows.Count)
      Rng.Copy Range("G" & i)
      i = i + Rng.Rows.Count
   Next Cl
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub sbeedle()
   Dim Rng As Range, Cl As Range
   Dim i As Long
   i = 3
   Set Rng = Range("C3:D" & Range("C" & Rows.Count).End(xlUp).Row)
   For Each Cl In Range("A3", Range("A" & Rows.Count).End(xlUp))
      Cl.Copy Range("F" & i).Resize(Rng.Rows.Count)
      Rng.Copy Range("G" & i)
      i = i + Rng.Rows.Count
   Next Cl
End Sub
Thank you so VERY much!! This was great! I changed a couple things to include the first store and item number (C3 to C2 and A3 to A2) and changed integer to 2 to line it up at the top but what you did was incredible and was perfect! I can't begin to tell you how much time this is going to save me. Serious heartfelt thanks!
 
Upvote 0
How about
VBA Code:
Sub sbeedle()
   Dim Rng As Range, Cl As Range
   Dim i As Long
   i = 3
   Set Rng = Range("C3:D" & Range("C" & Rows.Count).End(xlUp).Row)
   For Each Cl In Range("A3", Range("A" & Rows.Count).End(xlUp))
      Cl.Copy Range("F" & i).Resize(Rng.Rows.Count)
      Rng.Copy Range("G" & i)
      i = i + Rng.Rows.Count
   Next Cl
End Sub
I realize now looking at the screenshot that the numbers being off was my fault as I had screen shot a sheet that was a bit different. Sorry that I implied you might have had something wrong - you were perfect, I was not! Thank you again!!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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