VBA for Userform to be stacked in a particular sheet

blackorchids2002

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

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

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,166
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]
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,255
Office Version
2013
Platform
Windows
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:

blackorchids2002

Board Regular
Joined
Dec 29, 2011
Messages
117
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]
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,166
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.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,255
Office Version
2013
Platform
Windows
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
 

Forum statistics

Threads
1,081,556
Messages
5,359,546
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top