Copy Table to last row of table on other Worksheet

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
184
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a PayData table on individual worksheets (named for the Employee they belong to). I need to create a Macro that will copy the contents (not the header row) of the PayData table and write it to the last row of the BalanceTable. How is this easily achieved?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Something like this:

*BalanceTable sheet name is assumed to be "Master" in the below

VBA Code:
Sub Copy_Sheets_To_Master()

Dim wb As Workbook
Dim ws As Worksheet
Dim i, LastRowa, LastRowd As Long
Dim WSname As String

Set wb = ActiveWorkbook

For Each ws In wb.Sheets

If ws.Name <> "Master" Then

WSname = ws.Name

LastRowa = ws.Cells(Rows.Count, "A").End(xlUp).Row
LastRowd = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row

ws.Range("A14:A" & LastRowa).Copy
Sheets("Master").Range("A" & LastRowd + 2).PasteSpecial Paste:=xlPasteValues
Sheets("Master").Range("A" & LastRowd + 1).Value = WSname

End If

Next ws

End Sub
 
Upvote 0
This is amazing...One tweak if you could be so kind as to help me a little further....After looking at the PayData table I only need to pull the last row and apply it to the BalanceTable on the Balance Tables worksheet. How hard is it to make that adjustment?
 
Upvote 0
See how this goes. Can't test atm I'm afraid.

If it fails, what columns are these tables in? And what is the first row of them?

Cheers

VBA Code:
Sub Copy_Sheets_To_Master()

Dim wb As Workbook
Dim ws As Worksheet
Dim i, LastRowa, LastRowd As Long
Dim WSname As String

Set wb = ActiveWorkbook

For Each ws In wb.Sheets

If ws.Name <> "Master" Then

WSname = ws.Name

LastRowa = ws.Cells(Rows.Count, "A").End(xlUp).Row
LastRowd = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row

ws.Rows(LastRowa).Copy
Sheets("Master").Range("A" & LastRowd + 1).PasteSpecial Paste:=xlPasteValues

End If

Next ws

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,558
Latest member
aivin

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