I am writing a macro to transfer data from an input form to a storage table.
I have the rough code worked out, and it runs. Only if i have the destination sheet selected. If i try to run it from the sheet containing the form it throws the following error:
Run-time error '1004': Select method of Range class failed
But yet if i run the macro from the destination sheet it executes flawlessly.
Here is the code:
Sub ExpFormCharge()
Dim pasteCell As Range
Range("expenseTbl").ListObject.ListRows.Add AlwaysInsert:=False
Range("ETBMARKER").Offset(-1, 0).Select
Range("ExpFormBackend").Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
The backend table is filled by another macro and this table is then copied and pasted into a new row in the expense table(the storage table). The line that is highlighted by the debug option is this one:
Range("ETBMARKER").Offset(-1, 0).Select
That refers to a marker, the total row of the storage table offset one so as to select the bottom row of the table.
This error occurs whenever a sheet other than the destination sheet is selected whether the code is executed from the vba window or from the macro selection pane.