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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,747
Messages
5,855,434
Members
431,732
Latest member
albertdi827

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