How to pass a workshhet name as a parameter into a subroutine ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone give me an example how to pass a workshhet name as a parameter
into a subroutine ?
I want to do same thing into different worksheets.
 
Can someone give me an example how to pass a workshhet name as a parameter
into a subroutine ?
I want to do same thing into different worksheets.

One example:


Sub CallingProcedure()

'If you know the name of the sheet
CalledProcedure "Sheet2"

'Or if you just want the action on the current sheet
CalledProcedure ActiveSheet.Name

End Sub



Sub CalledProcedure(SheetToActOn As String)

'Put the time into cell A1
Worksheets(SheetToActOn).Range("A1") = Now()

End Sub
 
Why pass the sheet name, why not the sheet object?

Sub CallingProcedure()

'If you know the name of the sheet
CalledProcedure Worksheets("Sheet2")

'Or if you just want the action on the current sheet
CalledProcedure ActiveSheet

End Sub



Sub CalledProcedure(SheetToActOn As Worksheet)

'Put the time into cell A1
SheetToActOn.Range("A1") = Now()

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Why pass the sheet name, why not the sheet object?

Because that's not what the OP asked for. In the absence of him/her
stating what s/he was planning to do with the sheet name, I prefer not
to make assumptions.
 
Hi Hank,

It was really a question for the OP, I should have included his name.

After all, with experience like ours (:-)), sometimes we can help by
suggesting an alternative approach

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top