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

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,119
Messages
5,640,218
Members
417,131
Latest member
Seanr19871

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
Top