VBA for Userform to be stacked in a particular sheet

blackorchids2002

Board Regular
Joined
Dec 29, 2011
Messages
138
Hi Masters,

Just a question, is it possible to display a userform and will remain in a particular sheet (ex. Sheet1)?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You could Show\Hide a userform when a sheet is Activated\Deactivated if that's what you mean?

Example in the Sheet1 code module:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Activate()
    UserForm1.Show vbModeless
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Deactivate()
    UserForm1.Hide
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Hi Masters,

Just a question, is it possible to display a userform and will remain in a particular sheet (ex. Sheet1)?

A UserForm is not part of the Excel basic worksheet platform. It is created on a different platform and is basically a separate window from the worksheet. You can use the Activate event to make a userform appear when a worksheet is activated:

Private Sub Worksheet_Activate()
UserForm1.Show
End Sub

This would give the appearance that the form is attached to it.

To keep the form from appearing when another sheet is slected:

Private Sub Worksheet_Deactivate()
Unload UserForm1
End Sub


These code snippets would go in the sheet code module of the particular sheet that you want the form to appear with.

A note of caution...While the userform is open in Modal form, you cannot make any manual changes to worksheets.
 
Last edited:
Upvote 0
Hi AlphaFrog,

Perfrect!!! This is what I'm looking for.

Thanks a lot for your time. :)

Cheers,
Lhe


You could Show\Hide a userform when a sheet is Activated\Deactivated if that's what you mean?

Example in the Sheet1 code module:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Activate()
    UserForm1.Show vbModeless
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]


[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] Worksheet_Deactivate()
    UserForm1.Hide
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
You're welcome and thank you for the feedback. You could thank JLGWhiz as well. Same solution a few minutes later, but no less deserving of gratitude.
 
Upvote 0
You're welcome and thank you for the feedback. You could thank JLGWhiz as well. Same solution a few minutes later, but no less deserving of gratitude.

Always happy to see somebody solve their problems, no matter who gets the accolades.
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top