View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default 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 *