Capture name of last worksheet opened

S

Sliman

I need to be able to run a macro when I open worksheet only if i
opened worksheet from a particual sheet.

if i open sheet 1 and was on sheet 2 i want macro in sheet 1 "on open"
to run
if i open sheet 1 and was on sheet 3 i want macrro in sheet 1 "on
open" no to run
 
G

Guest

something like this in the ThisWorkbook code module:


Dim strPreviousSheet As String
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet1" And strPreviousSheet = "Sheet2" Then
'Call a sub defined in sheet1
Sheets(Sh.Name).test
End If
strPreviousSheet = Sh.Name
End Sub
 

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