ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   activating the previous sheet (https://www.excelbanter.com/excel-programming/401647-activating-previous-sheet.html)

[email protected]

activating the previous sheet
 
I am trying to activate the previous sheet in my code. My macro does
some code from the current sheet but then needs to pull some
information from the previous sheet. I get an error when I insert the
line
ActiveSheet.Previous.Select
Is this not correct?

JLGWhiz

activating the previous sheet
 
It worked for me. What error did you get?

" wrote:

I am trying to activate the previous sheet in my code. My macro does
some code from the current sheet but then needs to pull some
information from the previous sheet. I get an error when I insert the
line
ActiveSheet.Previous.Select
Is this not correct?


[email protected]

activating the previous sheet
 
On Nov 25, 3:37 pm, JLGWhiz wrote:
It worked for me. What error did you get?

" wrote:
I am trying to activate the previous sheet in my code. My macro does
some code from the current sheet but then needs to pull some
information from the previous sheet. I get an error when I insert the
line
ActiveSheet.Previous.Select
Is this not correct?


I changed things around...I think it is because my previous sheet was
hidden.

[email protected]

activating the previous sheet
 
On Nov 25, 3:37 pm, JLGWhiz wrote:
It worked for me. What error did you get?

" wrote:
I am trying to activate the previous sheet in my code. My macro does
some code from the current sheet but then needs to pull some
information from the previous sheet. I get an error when I insert the
line
ActiveSheet.Previous.Select
Is this not correct?


The previous sheet was a hidden sheet. I think that is why it would
not work. I inserted
ActiveSheet.Previous.Visible = True
ActiveSheet.Previous.Select
and I didn't get an error...however, my code did not do what I wanted
it to. Back to the drawing board!

Dave Peterson

activating the previous sheet
 
First, you don't usually have to .select or .activate a sheet to work on it.

But this may do what you want:

Option Explicit
Sub testme()
Dim sCtr As Long
Dim FoundIt As Boolean
FoundIt = False
For sCtr = ActiveSheet.Index - 1 To 1 Step -1
If Sheets(sCtr).Visible = True Then
Sheets(sCtr).Select
FoundIt = True
Exit For
End If
Next sCtr

If FoundIt = False Then
MsgBox "Error showing previous sheet"
End If
End Sub



wrote:

On Nov 25, 3:37 pm, JLGWhiz wrote:
It worked for me. What error did you get?

" wrote:
I am trying to activate the previous sheet in my code. My macro does
some code from the current sheet but then needs to pull some
information from the previous sheet. I get an error when I insert the
line
ActiveSheet.Previous.Select
Is this not correct?


The previous sheet was a hidden sheet. I think that is why it would
not work. I inserted
ActiveSheet.Previous.Visible = True
ActiveSheet.Previous.Select
and I didn't get an error...however, my code did not do what I wanted
it to. Back to the drawing board!


--

Dave Peterson


All times are GMT +1. The time now is 06:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com