This is probably really simple, but I'll ask anyway.
Having looked in the archives yesterday to find a simple piece of code to copy a cell and paste it over a range, I have the following code that works in a spreadsheet by itself:
Sheets("Sheet1").Range("D5").Copy Sheets("Sheet1").Range("D5", Range("D5").Offset(0, 30))
The 30 will (eventually) be replaced by a variable defined elsewhere in the main piece of code.
However, when it is pasted into the main spreadsheet, even as a standalone macro rather than integrated in the other code, it almost always fails with a 'Run-time error '1004': Application-defined or object-defined error' (this caused me no end of problems yesterday as I was attemting to use it in the main spreadsheet rather than a stand-alone one, so kept assuming that the code was failing completely).
I know I can use variables to define the range, but was wondering if there is a simple alteration I could make to make this code work, as it's far simpler in structure.
Cheers
James
Having looked in the archives yesterday to find a simple piece of code to copy a cell and paste it over a range, I have the following code that works in a spreadsheet by itself:
Sheets("Sheet1").Range("D5").Copy Sheets("Sheet1").Range("D5", Range("D5").Offset(0, 30))
The 30 will (eventually) be replaced by a variable defined elsewhere in the main piece of code.
However, when it is pasted into the main spreadsheet, even as a standalone macro rather than integrated in the other code, it almost always fails with a 'Run-time error '1004': Application-defined or object-defined error' (this caused me no end of problems yesterday as I was attemting to use it in the main spreadsheet rather than a stand-alone one, so kept assuming that the code was failing completely).
I know I can use variables to define the range, but was wondering if there is a simple alteration I could make to make this code work, as it's far simpler in structure.
Cheers
James