Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically Run a macro when a worksheet is selected
"Stephen Hartman" wrote in message ... Is there a bit of code that will automatically run a macro when I select the worksheet that contains the macro? That work's great thanks! One other question.... If I have 2 sheets, I need code in sheet 2 that will check the last row used in sheet 1 and then return that value as a variable so it can be used throughout the code in sheet 2. Any help would be greatly appreciated! |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Automatically Run a macro when a worksheet is selected
"Stephen Hartman" wrote in message
... If I have 2 sheets, I need code in sheet 2 that will check the last row used in sheet 1 and then return that value as a variable so it can be used throughout the code in sheet 2. Any help would be greatly appreciated! Hi Stephen, If you mean you want the last row number, here's one way to do it. Note that in some cases the UsedRange method will return an area greater than the actual area in use, in which case a more complex method of determining the last row is required. ------------------------- In Sheet2 Code Module ------------------------- Private mlLastRow As Long Private Sub Worksheet_Activate() mlLastRow = Sheet1.UsedRange.Rows.Count End Sub -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to run specific macro on selected worksheet? | Excel Discussion (Misc queries) | |||
Automatically copy selected information from one worksheet to anot | Excel Discussion (Misc queries) | |||
Macro to Sort automatically when file/save is selected | Excel Discussion (Misc queries) | |||
How to run a macro when a worksheet is selected | Excel Worksheet Functions | |||
Automatically Run a macro when a worksheet is selected | Excel Programming |