Sheet change event to return sheet name just left

S

Spike

Does anyone have any idea how I can get the name of a worksheet that I have
just moved from. So if I am in Sheet1 and move to Sheet2, how do I get a
macro to return Sheet1. In all the Events I have looked at they all return
the name of the sheet that I have moved to not the sheet I have left.

Any help will be gratefully received
 
G

Gary''s Student

We need to remember it. In a standard module:

Public OldSheet As String
Public NewSheet As String

In the worksheet code area of every sheet:


Private Sub Worksheet_Activate()
If IsEmpty(OldSheet) Then
OldSheet = "x"
End If
MsgBox OldSheet
OldSheet = ActiveSheet.Name
End Sub
 
M

Mike Fogleman

Sub marine()
Dim prev As String

prev = ActiveSheet.Previous.Name
End Sub

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top