CodexBloom - Programming Q&A Platform

VBA: scenarios 1004 'Application-defined or object-defined scenarios' when using Copy method on a range in Excel

👀 Views: 3 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-09
vba excel runtime-error

Does anyone know how to I'm trying to debug Quick question that's been bugging me - I've searched everywhere and can't find a clear answer... I'm sure I'm missing something obvious here, but I'm working with a frustrating scenario while trying to copy data from one worksheet to another in Excel using VBA. My code is intended to copy a specified range from 'Sheet1' to 'Sheet2', but I keep getting the behavior `Run-time behavior '1004': Application-defined or object-defined behavior` when I reach the `Copy` method. Here's the relevant code snippet: ```vba Sub CopyData() Dim sourceSheet As Worksheet Dim destinationSheet As Worksheet Set sourceSheet = ThisWorkbook.Worksheets("Sheet1") Set destinationSheet = ThisWorkbook.Worksheets("Sheet2") ' Assuming data is in A1 to A10 sourceSheet.Range("A1:A10").Copy destinationSheet.Range("B1") End Sub ``` I double-checked that both sheets exist and that the range in 'Sheet1' contains values. To troubleshoot, I added behavior handling, and it points directly to the `Copy` line. I also tried manually copying the data in Excel to see if there was something wrong with the sheets themselves, and it worked without scenario. Another thing I noticed is that if I change the destination to another cell, say `C1`, I still receive the same behavior. I've ensured the sheets are not protected and the workbook is not in a read-only state. Would anyone know why I might be getting this behavior? Is there something I'm overlooking with the `Copy` method, or could there be an scenario with Excel settings? Any insights would be greatly appreciated! For context: I'm using Vba on Linux. Has anyone else encountered this? I'm working on a API that needs to handle this. I'm developing on CentOS with Vba. Any feedback is welcome!