Macro for copying and inserting copied cells on multiple spreadsheets

EdieS

New Member
Joined
Jun 16, 2011
Messages
20
I have multiple spreadsheets that have cells linked between the spreadsheets. I would like with a macro to select the last row with data in in one spreadsheet and the 6 rows above that row and Copy and Insert copied cells below the last row with data and then loop through the other spreadsheets doing the same copy/insert so that the linked cells stay in sync.

Thanks for any help.

Edie
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Code:
Sub Copy_Last6()

    Dim ws As Worksheet
    Dim Lastrow As Long
    
    For Each ws In Worksheets
    
        Lastrow = 0
        On Error Resume Next
        Lastrow = ws.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
        On Error GoTo 0
        
        If Lastrow >= 6 Then
            ws.Rows(Lastrow - 5).Resize(6).Copy Destination:=ws.Rows(Lastrow + 1).Resize(6)
        End If
    
    Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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