Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
yigalb
 
Posts: n/a
Default How to pass a workshhet name as a parameter into a subroutine ?

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.
  #2   Report Post  
Hank Scorpio
 
Posts: n/a
Default

On Sat, 8 Jan 2005 02:49:05 -0800, yigalb
wrote:

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



---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *
  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

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)


"Hank Scorpio" wrote in message
...
On Sat, 8 Jan 2005 02:49:05 -0800, yigalb
wrote:

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



---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *



  #4   Report Post  
Hank Scorpio
 
Posts: n/a
Default

On Sat, 8 Jan 2005 15:19:07 -0000, "Bob Phillips"
wrote:

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.

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



---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *
  #5   Report Post  
Bob Phillips
 
Posts: n/a
Default

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

"Hank Scorpio" wrote in message
...
On Sat, 8 Jan 2005 15:19:07 -0000, "Bob Phillips"
wrote:

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.

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



---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
* Please keep all replies in this Newsgroup. Thanks! *



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wildcard parameter in excel BJC Excel Discussion (Misc queries) 1 December 24th 04 12:16 PM
How to use a Access Query that as a parameter into Excel database query Karen Middleton Excel Discussion (Misc queries) 1 December 13th 04 07:54 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"