Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default What was ActiveSheet before changed to new sheet?

I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"), then
they click the tab to go to the "Prices" sheet. How can I tell what sheet
they're comming FROM - in this case the "Main" sheet? In the Workbook and
the Worksheet events Activate and Deactivate, I check the Sheet parameter
(SH) and it always shows "Prices", the sheet they're going too.

Thanks for your help!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default What was ActiveSheet before changed to new sheet?

Working OK here.
2 sheets, in the sheet1 code module:

Private Sub Worksheet_Activate()
MsgBox "activate", , "sheet1"
End Sub

Private Sub Worksheet_Deactivate()
MsgBox "de-activate", , "sheet1"
End Sub

in the sheet2 code module:

Private Sub Worksheet_Activate()
MsgBox "activate", , "sheet2"
End Sub

Private Sub Worksheet_Deactivate()
MsgBox "de-activate", , "sheet2"
End Sub

First I get the Deactivate from the sheet I came from, then the Activate
event
from the sheet I went to. Try for yourself.


RBS


"Tom L" wrote in message
...
I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"),
then they click the tab to go to the "Prices" sheet. How can I tell what
sheet they're comming FROM - in this case the "Main" sheet? In the
Workbook and the Worksheet events Activate and Deactivate, I check the
Sheet parameter (SH) and it always shows "Prices", the sheet they're going
too.

Thanks for your help!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 132
Default What was ActiveSheet before changed to new sheet?

Tom, this code indicates one approach. Put it in your ThisWorkbook module.

Regards,
Bill


Private g_strLastSheetName As String

Private Sub Workbook_Open()
g_strLastSheetName = ThisWorkbook.ActiveSheet.Name
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call MsgBox("last sheet: " & g_strLastSheetName)
g_strLastSheetName = ThisWorkbook.ActiveSheet.Name
End Sub




"Tom L" wrote:

I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"), then
they click the tab to go to the "Prices" sheet. How can I tell what sheet
they're comming FROM - in this case the "Main" sheet? In the Workbook and
the Worksheet events Activate and Deactivate, I check the Sheet parameter
(SH) and it always shows "Prices", the sheet they're going too.

Thanks for your help!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default What was ActiveSheet before changed to new sheet?

You could try this in the thisworkbook module -

Dim mSh As Object
Dim mShtName As String

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim sName As String
Dim sMsg As String

On Error Resume Next
sName = mSh.Name
On Error GoTo 0

If sName = "" Then
sMsg = mShtName & " has just been deleted"
Else
sMsg = mShtName & " deactivated"
End If
MsgBox sMsg, , Sh.Name & " activated"

End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set mSh = Sh
mShtName = Sh.Name
End Sub

Regards,
Peter T

"Tom L" wrote in message
...
I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"),

then
they click the tab to go to the "Prices" sheet. How can I tell what sheet
they're comming FROM - in this case the "Main" sheet? In the Workbook and
the Worksheet events Activate and Deactivate, I check the Sheet parameter
(SH) and it always shows "Prices", the sheet they're going too.

Thanks for your help!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default What was ActiveSheet before changed to new sheet?

Hi Tom

Main sheet: right clik on tab - View Code and place below.

Take a close look at the 2 arrows. Left: Object and right: Procedure.


Option Explicit

Private Sub Worksheet_Deactivate()
MsgBox Me.Name
End Sub


Enjoy
--
Best Regards
Joergen Bondesen


"Tom L" wrote in message
...
I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"),
then they click the tab to go to the "Prices" sheet. How can I tell what
sheet they're comming FROM - in this case the "Main" sheet? In the
Workbook and the Worksheet events Activate and Deactivate, I check the
Sheet parameter (SH) and it always shows "Prices", the sheet they're going
too.

Thanks for your help!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default What was ActiveSheet before changed to new sheet?

Thanks everyone for your code examples, it gave me the solution I needed!!

Tom


"Tom L" wrote in message
...
I've been searching for hours, can't find a solution but it's probably
simple...how can I tell what sheet was the ActiveSheet BEFORE they changed
to the current activesheet.

Example: User is on a particular sheet (let's say they're on "Main"),
then they click the tab to go to the "Prices" sheet. How can I tell what
sheet they're comming FROM - in this case the "Main" sheet? In the
Workbook and the Worksheet events Activate and Deactivate, I check the
Sheet parameter (SH) and it always shows "Prices", the sheet they're going
too.

Thanks for your help!



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
do some code after the sheet name is changed ARHangel Excel Discussion (Misc queries) 1 January 18th 08 10:39 AM
Select the ActiveSheet & the sheet next to it Dolphinv4 Excel Discussion (Misc queries) 1 December 11th 07 02:13 PM
Check Activesheet for chart sheet or work sheet NSK Charts and Charting in Excel 1 July 17th 07 09:00 PM
My ActiveX control does not respond when i draw it on a excell sheet, using ActiveSheet.OLEObject.Add Nikhil Joshi[_2_] Excel Programming 0 August 11th 06 02:57 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM


All times are GMT +1. The time now is 08:35 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"