Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default How do you get a macro to reference the worksheet it is being run

How do you get a macro to reference the worksheet it is being run from?

How do you write in the macro formula "take data from sheet macro is being
run from" (macro is being run from a submit button on a sheet - but I would
like to make a template and have lots of similiar sheets so I need it to
identify where it is being run from - not reference the template)

Hope this makes sense - if not please ask me to clarify - I have posted a
few similiar questions - but not had a single answer - if I am going about it
the wrong way, please let me know.

Michelle
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 103
Default How do you get a macro to reference the worksheet it is being run

On Tue, 11 Aug 2009 01:57:02 -0700, Michelle D
wrote:

How do you get a macro to reference the worksheet it is being run from?

How do you write in the macro formula "take data from sheet macro is being
run from" (macro is being run from a submit button on a sheet - but I would
like to make a template and have lots of similiar sheets so I need it to
identify where it is being run from - not reference the template)


Since the button is going to be on the ActiveSheet, all you need to do
is use that as a reference. You can also store it as a variable if you
need to, like so:

Private Sub CommandButton1_Click()

Dim wks As Excel.Worksheet

Set wks = ActiveSheet

'Do other stuff

MsgBox wks.Name

Set wks = Nothing

End Sub


---------------------------------------------------------
Hank Scorpio
scorpionet who hates spam is {Between permanent e-mail addresses at this time, which makes the next line of my signature redundant}
* Please keep all replies in this Newsgroup. Thanks! *
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default How do you get a macro to reference the worksheet it is being run

ThisWorkbook.ActiveSheet.Name
will return the active sheetname of the workbook where the macro resides

MsgBox ActiveWorkbook.ActiveSheet.Name
will return the currently active sheetname of the active workbook

''Try the below macro
Sub Macro()
Dim wb As Workbook
Dim ws As Worksheet

'Referencing the workbook where the macro resides
Set wb = ThisWorkbook
Set ws = wb.ActiveSheet
MsgBox ws.Name

'Referencing the active activeworkbook
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
MsgBox ws.Name
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Michelle D" wrote:

How do you get a macro to reference the worksheet it is being run from?

How do you write in the macro formula "take data from sheet macro is being
run from" (macro is being run from a submit button on a sheet - but I would
like to make a template and have lots of similiar sheets so I need it to
identify where it is being run from - not reference the template)

Hope this makes sense - if not please ask me to clarify - I have posted a
few similiar questions - but not had a single answer - if I am going about it
the wrong way, please let me know.

Michelle

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
Macro to Create New Worksheet and Reference Cell in Old Worksheet As Tab Name - "Object Required" Error [email protected] Excel Discussion (Misc queries) 4 September 25th 06 01:35 PM
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. [email protected] Excel Discussion (Misc queries) 0 September 22nd 05 04:39 PM
Reference the worksheet from a multiple worksheet range function ( DBickel Excel Worksheet Functions 1 May 28th 05 03:49 AM
Can the offset worksheet function reference another worksheet AlistairJ Excel Worksheet Functions 2 May 9th 05 06:18 PM
Macro to Reference Column Next to Current Reference dolphinv4 Excel Discussion (Misc queries) 2 April 11th 05 08:36 AM


All times are GMT +1. The time now is 09:59 PM.

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"