Passing ActiveSheet to sub

Richard Fox

Board Regular
Joined
Oct 30, 2003
Messages
77
I'm trying to pass the active sheet to a routine but I'm having object problems. Not sure what to do.

Code:
Module_CurrentDisc
Sub Disc()
        Sheets("5S REFER").Select
        Module_CurrentDisc.CopyIOU (ActiveSheet) ' ERROR OCCURS HERE

        Sheets("5G REFER").Select
        Module_CurrentDisc.CopyIOU (ActiveSheet)

        Sheets("COMPL 24").Select
        Module_CurrentDisc.CopyIOU (ActiveSheet)
End Sub

Sub CopyIOU(ByVal Sh As Object)
      Msgbox("Do stuff to ActivSheet")
End Sub

EDIT:
I guess I should mention that the current sheet will change several times during the routine, so that's why I want to pass the sheet to it. I want to be able to revert to the calling sheet.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
So, I don't understand why you have to pass the activesheet to the calling sheet. If the only reason why, is to revert to the calling sheet, then why don't you code it like this:

Module_CurrentDisc
Sub Disc()
Sheets("5S REFER").Select
CopyIOU

Sheets("5G REFER").Select
CopyIOU

Sheets("COMPL 24").Select
CopyIOU
End Sub

Sub CopyIOU()
ShName=ActiveSheet.Name
Msgbox("Do stuff to ActivSheet")
Worksheets(ShName).Activate
End Sub

Cheers, Glenn.
 
Upvote 0
Thank you,
I tried several different ways to save the sheet name, but was unsuccessful. Now I can delete about 6 pages of repeated code.
 
Upvote 0

Forum statistics

Threads
1,203,489
Messages
6,055,722
Members
444,814
Latest member
AutomateDifficulty

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