Copy Used Range to first blank row on another sheet in same workbook

blbat

Active Member
Joined
Mar 24, 2010
Messages
338
Office Version
  1. 2016
  2. 2013
I'm getting a: "Method 'Range' of object_'Worksheet' failed" error message on the following code. it works up to the .Copy portion but I'm definitely doing something wrong with the Destination. Any help would be appreciated!

Code:
Private Sub CommandButton1_Click()

Dim mySheetW As Worksheet, mySheetT As Worksheet, LastRow As Long, LastCol As Long, LastRowT As Long, LastColT As Long

Set mySheetT = ActiveWorkbook.Worksheets("working")                              'Destination Sheet
Set mySheetW = ActiveWorkbook.ActiveSheet                                             'Macro called from this Sheet
LastRow = mySheetW.Cells(Rows.Count, 1).End(xlUp).Row                           'Last Row of Active Sheet
LastCol = mySheetW.Cells(1, Columns.Count).End(xlToLeft).Column              'Last Column of Active Sheet
LastRowT = mySheetT.Cells(Rows.Count, 1).End(xlUp).Row                          'Last Row of Destination Sheet
LastColT = mySheetT.Cells(1, Columns.Count).End(xlToLeft).Column             'Last Column of Destination Sheet


mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Copy Destination:=mySheetT.Range(LastRowT, LastColT).Paste

'No Cigar!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Simply remove the .Paste from the end of the line
 
Upvote 0
Thx for reply Fluff....removed the .Paste and same error persists.
 
Upvote 0
Fluff- (or anyone)
if you're still willing to help on this, I just got back to working on this problem and am having difficulty.
Still receiving Run-time error '1004'
Method 'Range' of object '_WorkSheet' failed

The message box correctly reports the destination sheet last row, but it fail when I execute the rest of the code.

what I am doing wrong here?

Code:
Private Sub CommandButton1_Click()

Dim mySheetW As Worksheet, mySheetT As Worksheet, LastRow As Long, LastCol As Long, LastRowT As Long, LastColT As Long

Set mySheetT = ActiveWorkbook.Worksheets("working") 'Destination Sheet
Set mySheetW = ActiveWorkbook.ActiveSheet 'Macro called from this Sheet
LastRow = mySheetW.Cells(Rows.Count, 1).End(xlUp).Row 'Last Row of Active Sheet
LastCol = mySheetW.Cells(1, Columns.Count).End(xlToLeft).Column 'Last Column of Active Sheet
LastRowT = mySheetT.Cells(Rows.Count, 1).End(xlUp).Row 'Last Row of Destination Sheet
LastColT = mySheetT.Cells(1, Columns.Count).End(xlToLeft).Column 'Last Column of Destination Sheet

'Next is select working Range WITHOUT Title Row!
'****************************
'mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Select


MsgBox (LastRowT) 'reports correct Last Row of Destination Sheet

'mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Copy Destination:=mySheetT.Range(LastRowT, LastColT)

mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Copy Destination:=mySheetT.Range(LastRowT + 1, LastColT)
'+1 intended to make destination row one down from last used Row

'Still No Cigar!

End Sub
 
Upvote 0
It should be
Code:
mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Copy Destination:=mySheetT.[COLOR=#ff0000]Cells[/COLOR](LastRowT + 1, LastColT)
But do you really want to paste the used range into sheetT starting at the last used column, or starting in col A?
 
Last edited:
Upvote 0
Thanks...that stopped the error, in fact there is no error at all, but the data is not getting copied into the destination sheet.

I don't need to have some sort of "Paste" method in there?
 
Upvote 0
Could you answer my question in post#5?
 
Upvote 0
****! sorry Fluff, I totally missed your question and it's an extremely good one!! LOL, it was indeed pasting it after the last column. I meant for it to paste starting in column A

Thanks so much for all your patience.
this works:
Code:
mySheetW.UsedRange.Offset(1).Resize(LastRow - 1, LastCol - 1).Copy Destination:=mySheetT.Cells(LastRowT + 1, LastColT - 35)
 
Upvote 0
Glad to help & thanks for the feedback.

I would recommend changing it to
Code:
mySheetT.Cells(LastRowT + 1, 1)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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