Trying to paste to a sheet I am not on.

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
When trying to paste to target when I am not on that sheet, I get an error. Can anyone help, I do not understand why this is not working.


Sub rangeset()
Dim N As Long, NN As Long
Dim M As Long, col As Long
Dim s As String
Dim target As Range, source As Range
Set sh1 = ActiveWorkbook.Sheets("Output")
Set sh2 = ActiveWorkbook.Sheets("DataSet")
Application.Calculation = xlCalculationManual
Set target = ActiveCell
sh2.Activate
Call PericopeHeader

Sub PericopeHeader()
If IsNumeric(Left(ActiveCell.Text, 1)) = True Then
ActiveCell.Copy
sh1.[target].PasteSpecial <<<<< I get an error here saying object is required.
ActiveCell.Offset(1, 0).Select
End If
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Ok, I figured it out. Have to define target as a variable in the declarations section, and not within the routine. Variable loses its value once it is passed to the subroutine.

Thank you me.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

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