Copy Paste to last row

thedeadzeds

Active Member
Joined
Aug 16, 2011
Messages
442
Office Version
  1. 365
Platform
  1. Windows
Sorry to post this, I have searched on this site but cant' find the easiest solution.

I just want to copy all data from the Master sheet columns A to AL based on the last row being AL of the Master sheet (excluding the headers) to the last row of the All Data sheet based on the last row being AL of the All Data Sheet.

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How's this work?

VBA Code:
Sub CopyOver()

Dim shtMaster As Worksheet
Dim shtAllData As Worksheet
Dim lngLastMasterRow As Long
Dim lngLastADRow As Long
Dim rngPaste As Range

With shtAllData

  lngLastADRow = .Range("A1").End(xlDown).Row
  Set rngPaste = .Range("A" & lngLastADRow)

End Sub

With shtMaster

  lngLastMasterRow = .Range("A1").End(xlDown).Row
  .Range("A2:AL" & lngLastMasterRow).Copy rngPaste

End With

End With
 
Upvote 0
How's this work?
I posted that too hastily. Here's a better version:

VBA Code:
Sub CopyOver()

Dim shtMaster As Worksheet
Dim shtAllData As Worksheet
Dim lngLastMasterRow As Long
Dim lngLastADRow As Long
Dim rngPaste As Range

Set shtMaster = ThisWorkbook.Sheets("Master")
Set shtAllData = ThisWorkbook.Sheets("All Data")

With shtAllData

  lngLastADRow = .Range("A1").End(xlDown).Row + 1
  Set rngPaste = .Range("A" & lngLastADRow)

End Sub

With shtMaster

  lngLastMasterRow = .Range("A1").End(xlDown).Row
  .Range("A2:AL" & lngLastMasterRow).Copy rngPaste

End With

Set shtMaster = Nothing
Set shtAllData = Nothing

End Sub
 
Upvote 0
Thanks for this but it doesn't seem to be doing anything? I've changed end sub in the middle of the code to end with but I cant' see that this actually copying and pasting the data when I run it.
 
Upvote 0
How about
VBA Code:
Sub thedeadzeds()
   With Sheets("Master")
      .Range("A2:AL" & .Range("AL" & Rows.Count).End(xlUp).Row).Copy Sheets("All Data").Range("AL" & Rows.Count).End(xlUp).Offset(1, -37)
   End With
End Sub
 
Upvote 0
Solution
Thank you fluff this works perfectly. Just out of interest what does -37 do and also I have managed to write some code below with works but doesnt find the last row from the Master sheet correctly. It seems to select more than the last row even thought there is no data below that.

Thanks

VBA Code:
Sub Copy()

Dim LR1 As Long
Dim LR2 As Long

LR1 = Cells(Rows.Count, 1).End(xlUp).Row
LR2 = Cells(Rows.Count, 1).End(xlUp).Row


Sheets("Master").Select
range("A2:AL" & LR1).Copy

Sheets("All Data").Select
range("A" & LR2 + 1).PasteSpecial


End Sub
 
Last edited:
Upvote 0
Te -37 is offsetting the range by 37 columns to the left taking it back to column A
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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