VBA: Copy one cell and paste every other row until the end

NikoleJay

New Member
Joined
May 9, 2020
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi!

I am creating a product that reorganizes a report. I have figured out most of what I want to do, but have not found an example of a code I know how to edit to my needs for one of the commands.

I need to be able to copy row 5 (which is merged from columns A through J with G and H hidden) and paste that into every other row. This will be a report that is run weekly and will have a changing number of rows, so I also need it to stop pasting after the last row with data.

Basically, I need to turn this:
Doc NumberTransaction Type#Operation DateOperation NoNSNNounQuantityCreated By
xxxxxxxxxxxxxxxxxx5/7/2020 19:00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx33EAxxxxxxxxxx
Remarks:_______________________
xxxxxxxxxxxxxxxxxx5/7/2020 19:00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx33EAxxxxxxxxxx
xxxxxxxxxxxxxxxxxx5/7/2020 19:00xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx33EAxxxxxxxxxx

Into this (with merged cells):
Doc NumberTransaction Type#Operation DateOperation NoNSNNounQuantityCreated By
XXXXXXXXXXXXXXXXXXXXXXXX5/5/2020 19:41XXXXXXXXXXXXXXXXX1EAXXXXXXXX
Remarks:_______________________
XXXXXXXXXXXXXXXXXXXXXXXX5/5/2020 19:41XXXXXXXXXXXXXXXXX1EAXXXXXXXX
Remarks:_______________________
XXXXXXXXXXXXXXXXXXXXXXXX5/5/2020 19:41XXXXXXXXXXXXXXXXX1EAXXXXXXXX
Remarks:_______________________

I attached pictures as well. Any help will be greatly appreciated!!
 

Attachments

  • To This.jpg
    To This.jpg
    132 KB · Views: 10
  • From This.jpg
    From This.jpg
    129.3 KB · Views: 11

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Welcome to the Board!

Try this:
VBA Code:
Sub MyCopyMacro()

    Dim r As Long

    Application.ScreenUpdating = False
    
'   Set initial r value
    r = 6
    
'   Do Loop
    Do
'       Copy row
        If Cells(r, "A") <> "" Then
            Rows(5).Copy Cells(r + 1, "A")
'       Else exit loop
        Else
            Exit Do
        End If
'       Increment row by 2
        r = r + 2
    Loop
        
    Application.ScreenUpdating = True
    
    MsgBox "Macro complete!"
    
End Sub
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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