View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond[_2_] Robin Hammond[_2_] is offline
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