PDA

View Full Version : Solved: select previous sheet that I viewed



av8tordude
04-04-2011, 10:42 AM
I'm using this code that selects sheet f2106 before it prints. How do i select the previous sheet i was viewing after the code finishes?

i.e.
Sheet1 displayed.
when the code finishes
re-select sheet1



With Sheets("f2106")
.Select
.PageSetup.PrintArea = "A1:AC36"
Application.Dialogs(xlDialogPrint).Show
End With

av8tordude
04-04-2011, 10:50 AM
I found the answer...thanks


ActiveSheet.Previous.Select

Bob Phillips
04-04-2011, 10:53 AM
That doesn't select the sheet you were previously viewing, but the previous sheet in the tabs, and will fail if the activesheet is the first sheet.

av8tordude
04-04-2011, 11:01 AM
Actually that's not what I'm looking for. Still need help. That code selects the previous sheet in succession instead of selecting the sheet i was viewing.

av8tordude
04-04-2011, 11:11 AM
ok...I got it this time and I tested it..lol


Dim stLast As String
stLast = ActiveSheet.Name
Sheets("f2106").Range("B17") = ActiveSheet.Range("B7")
With Sheets("f2106")
.Select
.PageSetup.PrintArea = "A1:AC36"
Application.Dialogs(xlDialogPrint).Show
Sheets(stLast).Activate
End With

mdmackillop
04-04-2011, 01:14 PM
Another way


'in ThisWorkbook

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set LstSht = Sh
End Sub

'in Standard Module

Public LstSht As Worksheet

Sub GoToLast()
LstSht.Activate
End Sub

blade402
11-23-2013, 01:55 PM
Another way


'in ThisWorkbook
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set LstSht = Sh
End Sub

'in Standard Module
Public LstSht As Worksheet

Sub GoToLast()
LstSht.Activate
End Sub

I can't get that to work. It says object required
here


Sub GoToLast()
LstSht.Activate
End Sub

Bob Phillips
11-24-2013, 04:55 AM
Did you define LastSht, did you set it in the deactivate event?

snb
11-24-2013, 05:45 AM
or

Private Sub Workbook_SheetDeActivate(ByVal Sh As Object)
Me.BuiltinDocumentProperties("subject") = Sh.Name
End Sub

Sub M_previoussheet()
Application.Goto Sheets(ThisWorkbook.BuiltinDocumentProperties("subject").Value).Cells(1)
End Sub