Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 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.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default 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!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activating Sheet from a List Magnivy Excel Programming 11 May 31st 06 03:20 PM
Help with activating previous sheet johncassell[_53_] Excel Programming 1 May 10th 06 06:04 PM
autorun upon activating a sheet cdde[_6_] Excel Programming 0 November 10th 04 11:43 PM
Problem activating a sheet jowatkins[_6_] Excel Programming 1 January 19th 04 01:33 PM
Problem in activating a sheet Neeleshwar Thakur Excel Programming 1 December 18th 03 12:43 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"