I am trying to write a macro to insert special formulas, but keep getting a run-time error 1004 "PasteSpecial class method Range failed".
This macro comes directly from the "Recording Macros" provided by Excel.
Sub paste_formulas()
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End Sub
Here is the sequence of events:
- Manually select the cell range in the CSV A file and copy (CTRL + C).
- Switch to XLS file B and select a cell to copy the copied data.
- Click Macros and run personal.xlsm! paste_formulas
This is when I get the error. Why does this work manually when I copy / paste special formulas but don't execute a macro?
Note. I need this to work in the above sequence, regardless of the range that I copy (it will change from time to time), and regardless of where I paste the formulas (it will also change from time to time). In other words, hardcoding a fixed range for copy and / or paste will not work for me.
Thanks in advance for understanding why my code doesn't work or doesn't work.
source
share