Error copying range to another Workbook

Madmanz

New Member
Joined
Dec 14, 2017
Messages
7
I get an error "Application-defined or object-defined error" when running this code. It works fine if copied to the same workbook.

The culprit is ("C" & Rows.Count). What am I doing wrong? Any help would be much appreciated, thanks.


Code:
               Range("AB1").Resize(1, 5).Copy
               Workbooks("Day Book").Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
can you upload the excel sheet or mentioned the previous and end result you are expecting....



I get an error "Application-defined or object-defined error" when running this code. It works fine if copied to the same workbook.

The culprit is ("C" & Rows.Count). What am I doing wrong? Any help would be much appreciated, thanks.


Code:
               Range("AB1").Resize(1, 5).Copy
               Workbooks("Day Book").Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
 
Upvote 0
Alright, I have 2 forms for work. An Order Form for writing up customer details, job description, etc. and a Day Book that lists every job taken on a check list.

My goal is to transfer all the important details from the Order Form (Order Number, Customer Name, etc) to the Day Book as soon as the Order Form is completed. But I don't want any entries to be overwritten.
 
Upvote 0
I get an error "Application-defined or object-defined error" when running this code. It works fine if copied to the same workbook.

What happens if you add the file extension (change xlsm to suit)?

Code:
Workbooks("Day Book[COLOR="#FF0000"].xlsm[/COLOR]").Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats

Is the workbook Day Book open?

What file extension are both workbooks?
 
Last edited:
Upvote 0
The Order Form is a template file .xltm and the Day Book is .xls

Both workbooks are always open and adding the extension (.xls) gives me the same error.
 
Upvote 0
What happens with

Code:
Sub dddd()
    Range("AB1").Resize(1, 5).Copy
    With Workbooks("Day Book.xls").Sheets("Sheet1")
        .Range("C" & .Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
    End With
End Sub
 
Upvote 0
Ok got it working, thanks Mark. You got me thinking about file extensions and got me wondering what would happen if I change the file to .xlsm :)
 
Upvote 0
Did you test the code I posted (with and without the .xls in the code) before you changed it to xlsm?
 
Upvote 0
Oh wow, I just tried your code in a .xls file and it worked, i didn't realise that the part in bold was meant to refer to the outside workbook as well, thanks a ton :)

What happens with

Code:
Sub dddd()
    Range("AB1").Resize(1, 5).Copy
    With Workbooks("Day Book.xls").Sheets("Sheet1")
        .Range("C" & [B].Rows.Count[/B]).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
    End With
End Sub
 
Upvote 0
Oh wow, I just tried your code in a .xls file and it worked, i didn't realise that the part in bold was meant to refer to the outside workbook as well, thanks a ton :)

It doesn't need to if they are the same file type, or more accurately if you aren't mixing old and new file types.

What your code was doing was looking at the row count on the active sheet which because it was a xlsm has a row count of 1,048,576.

Xls only has 65,536 rows and so it was screaming Help! I don't have that many rows.
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,590
Members
449,039
Latest member
Arbind kumar

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