Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Selecting sheet after Userform

I have a Userform that is activated from one toolbar while any of 7 sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work and is
closed, I want to return to the sheet from which it was launched. Any ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Selecting sheet after Userform

Denny,

try this

In the declarations section at the top of your form module
Private shOrigin as worksheet

In UserForm_Initialize
Set shOrigin = ActiveSheet

In UserForm_Terminate
shOrigin.Select
Set shOrigin = Nothing

Robin Hammond
www.enhanceddatasystems.com


"Denny Behnfeldt" wrote in message
...
I have a Userform that is activated from one toolbar while any of 7 sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work and

is
closed, I want to return to the sheet from which it was launched. Any

ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting sheet after Userform

at the top of the userform module

Dim sh as Worksheet

in the initialize event

set sh = Activesheet

in the code that closes the userform

sh.Activate

--
Regards,
Tom Ogilvy

"Denny Behnfeldt" wrote in message
...
I have a Userform that is activated from one toolbar while any of 7 sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work and

is
closed, I want to return to the sheet from which it was launched. Any

ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Selecting sheet after Userform

Thanks for both responses.
For Tom's:
I am getting a "Run Time '91' Error, object variable or With Block variable
not set". This is when I put "sh.Activate" in the closing code of the Close
CommandButton I use.

"At the top of userform module" I assume is under (General), (Declarations).
I understand the logic, but must be missing something.

I tried Robin's solution also, and I don't get an error, but I don't get the
right sheet selected.

Any ideas what I'm missing?
Denny


"Tom Ogilvy" wrote in message
...
at the top of the userform module

Dim sh as Worksheet

in the initialize event

set sh = Activesheet

in the code that closes the userform

sh.Activate

--
Regards,
Tom Ogilvy

"Denny Behnfeldt" wrote in message
...
I have a Userform that is activated from one toolbar while any of 7

sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work

and
is
closed, I want to return to the sheet from which it was launched. Any

ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Selecting sheet after Userform

It sounds like you are not setting the original sheet correctly.

In the declarations section at the top of your form module(the very top line
of the code, above any subs or functions)

Private shOrigin as worksheet

In UserForm_Initialize
Set shOrigin = ActiveSheet
'add this just to check it is being set properly
Msgbox(shOrigin.Name)

In UserForm_Terminate
'add this to see what is happening
MsgBox(shOrigin.Name)

shOrigin.Select
Set shOrigin = Nothing

Robin Hammond
www.enhanceddatasystems.com


"Denny Behnfeldt" wrote in message
...
Thanks for both responses.
For Tom's:
I am getting a "Run Time '91' Error, object variable or With Block

variable
not set". This is when I put "sh.Activate" in the closing code of the

Close
CommandButton I use.

"At the top of userform module" I assume is under (General),

(Declarations).
I understand the logic, but must be missing something.

I tried Robin's solution also, and I don't get an error, but I don't get

the
right sheet selected.

Any ideas what I'm missing?
Denny


"Tom Ogilvy" wrote in message
...
at the top of the userform module

Dim sh as Worksheet

in the initialize event

set sh = Activesheet

in the code that closes the userform

sh.Activate

--
Regards,
Tom Ogilvy

"Denny Behnfeldt" wrote in message
...
I have a Userform that is activated from one toolbar while any of 7

sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work

and
is
closed, I want to return to the sheet from which it was launched. Any

ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting sheet after Userform

In the userform Module I had this code:

'----< Declarations -------------
Dim sh As Worksheet

'----< Code --------------------
Private Sub CommandButton1_Click()
' activate a random sheet
num = Int(Rnd() * Sheets.Count + 1)
Sheets(num).Activate
End Sub

Private Sub CommandButton2_Click()
sh.Activate
Unload Me
End Sub

Private Sub UserForm_Initialize()
Set sh = ActiveSheet
End Sub


works fine for me. I close the form with Commandbutton1

--
Regards,
Tom Ogilvy




"Denny Behnfeldt" wrote in message
...
Thanks for both responses.
For Tom's:
I am getting a "Run Time '91' Error, object variable or With Block

variable
not set". This is when I put "sh.Activate" in the closing code of the

Close
CommandButton I use.

"At the top of userform module" I assume is under (General),

(Declarations).
I understand the logic, but must be missing something.

I tried Robin's solution also, and I don't get an error, but I don't get

the
right sheet selected.

Any ideas what I'm missing?
Denny


"Tom Ogilvy" wrote in message
...
at the top of the userform module

Dim sh as Worksheet

in the initialize event

set sh = Activesheet

in the code that closes the userform

sh.Activate

--
Regards,
Tom Ogilvy

"Denny Behnfeldt" wrote in message
...
I have a Userform that is activated from one toolbar while any of 7

sheets
(MON, TUE, etc.) is active. When the Userform is done doing it's work

and
is
closed, I want to return to the sheet from which it was launched. Any

ideas
on how I would do this?

This newsgroup is incredibly helpful!
Thanks alot,
Denny








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
Centering A Userform On The Sheet John Calder New Users to Excel 3 July 30th 09 12:38 AM
userform freezes sheet teepee[_3_] Excel Discussion (Misc queries) 2 October 26th 08 04:12 PM
Selecting sheet with VB RobN[_2_] Excel Discussion (Misc queries) 14 May 23rd 08 01:36 AM
Selecting Last Sheet Bonbon Excel Worksheet Functions 17 February 22nd 06 04:16 PM
UserForm and combo box to another sheet Nigel Excel Discussion (Misc queries) 0 April 29th 05 09:41 AM


All times are GMT +1. The time now is 09:25 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"