Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

activating the previous sheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bramnizzle@gmail.com - 25 Nov 2007 20:17 GMT
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 - 25 Nov 2007 20:37 GMT
It worked for me.  What error did you get?

> 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?
bramnizzle@gmail.com - 25 Nov 2007 20:41 GMT
> It worked for me.  What error did you get?
>
[quoted text clipped - 5 lines]
> > ActiveSheet.Previous.Select
> > Is this not correct?

I changed things around...I think it is because my previous sheet was
hidden.
bramnizzle@gmail.com - 25 Nov 2007 20:43 GMT
> It worked for me.  What error did you get?
>
[quoted text clipped - 5 lines]
> > 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 - 25 Nov 2007 20:55 GMT
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

> > It worked for me.  What error did you get?
> >
[quoted text clipped - 12 lines]
> and I didn't get an error...however, my code did not do what I wanted
> it to.  Back to the drawing board!

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.