VBA copy cell ranges and paste each cell n times into a different sheet

Multim

New Member
Joined
Apr 17, 2024
Messages
6
Office Version
  1. 2021
Hello
I'm a VBA novice and normally can cobble something together but am stuck with this one.

I have a sheet called "Inventory Details" and a list of part numbers in cell A2 down, this will be a variable number of part numbers, I need each cell copied then pasted 6 times into a Sheet called " Routing Info" starting in A2 and the the next cell pasted 6 times below and so on.

Any assistance would be greatly appreciated.

"Inventory Details" Cells
Screenshot 2024-12-17 153428.png

" Routing Info" sheet final requirement
Screenshot 2024-12-17 153454.png


Thank you
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this:
VBA Code:
Sub MyCopyData()

    Dim wsInv As Worksheet
    Dim wsRtg As Worksheet
    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Set worksheet objects
    Set wsInv = Worksheets("Inventory Details")
    Set wsRtg = Worksheets("Routing Info")
    
'   Find last row in column A with data on Inventory Detils sheet
    lr = wsInv.Cells(wsInv.Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows starting on row 2
    For r = 2 To lr
'       Populate next 6 rows on Routing Info sheet
        wsRtg.Range(wsRtg.Cells(((r - 2) * 6) + 2, "A"), wsRtg.Cells(((r - 2) * 6) + 7, "A")).Value = wsInv.Cells(r, "A").Value
    Next r
        
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Hello
I'm a VBA novice and normally can cobble something together but am stuck with this one.

I have a sheet called "Inventory Details" and a list of part numbers in cell A2 down, this will be a variable number of part numbers, I need each cell copied then pasted 6 times into a Sheet called " Routing Info" starting in A2 and the the next cell pasted 6 times below and so on.

Any assistance would be greatly appreciated.

"Inventory Details" Cells
View attachment 120419
" Routing Info" sheet final requirement
View attachment 120420

Thank you
Or this.

VBA Code:
Private Sub subCopyParts()
Dim arr() As Variant
Dim i As Integer
Dim lngRow As Long
Dim ii As Integer

  With Worksheets("Inventory Details")
    arr = .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
  End With
  
  lngRow = 2
  
  For i = 1 To UBound(arr)
    For ii = 1 To 6
      Worksheets("Routing Info").Range("A" & lngRow).Value = arr(i, 1)
      lngRow = lngRow + 1
    Next ii
  Next i
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,700
Members
452,994
Latest member
Janick

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