Show or Hide|Unload a userform

Home/Excel VBA, VBA/Show or Hide|Unload a userform

Show or hide a userform means to display or hide a Userform. We use Show method of userform in a macro to display a userform. We use Hide method of userform or Unload statement in a macro to hide a userform. Please find the below example for better understand how to show or hide a userform on the worksheet.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Show a UserForm

Please find the following instructions and example to Show a UserForm on the Worksheet.

  1. place a command button on your worksheet.
  2. Double click on the command button.
  3. Now, you can see the following procedure. Please find the following screenshot.
  4. Private Sub CommandButton1_Click()
    End Sub
    
  5. Add the following code to the above procedure. Shown in the following.
  6. Private Sub CommandButton1_Click()
    UserForm1.Show
    End Sub
    
  7. Now, go to worksheet and click on the Command button to see the UserForm on the screen.

Show a UserForm while opening Excel File or Workbook

Here is the example code to Show a UserForm while opening Excel File or Workbook. Please find the below instructions.

  1. Go to Visual Basic Editor or Press Alt+F11
  2. In the Project Explorer,You can find The Workbook module.
  3. Select Workbook from the object drop down list(find left side)
  4. Select open from the procedure or event drop down list (find right side). Please find the following screenshot for the same.
  5. You can see Workbook Open procedure . Its is shown as follows.
  6. Private Sub Workbook_Open()
    End Sub
    
  7. Now, you can add the following code to the above event. It is shown in the following line.
  8. Private Sub Workbook_Open()
    UserForm1.Show
    End Sub
    

Hide a UserForm

When we hide the userform, it will just hide the userform and will not release the objects and variables from the memory. Where as Unload method will release the objects and variables from the memory.
Please find the following instructions and example to Hide a UserForm on the Worksheet.

  1. place a command button on your worksheet.
  2. Double click on the command button.
  3. Now, you can see the following procedure.
  4. Private Sub CommandButton1_Click()
    End Sub
    
  5. Add the following code to the above procedure. Shown in the following.
  6. Using Hide Method:

    Private Sub CommandButton1_Click()
    UserForm1. Hide
    End Sub
    

    Using Unload Method:

    Private Sub UserForm_Click()
    Unload Me
    End Sub
    

    When we click on the Userform, it will disappear from the screen.

  7. Now, go to worksheet and click on the Command button to hide or unload a UserForm on the screen.
  8. So, Hide method will be used when we want to hide the form temorarly and to show after sometime to the user. Where as unload will be used when it completes the task.
LIMITED TIME OFFER
By |October 2nd, 2015|Excel VBA, VBA|1 Comment

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

One Comment

  1. Venkat July 4, 2016 at 6:23 PM - Reply

    Dear Mr.P.N Rao !
    Is it possible to use enter key on a commandbutton on an excel sheet instead of click() ? if so how ? I am a regular visitor of your site and blog..

    Regards

Leave A Comment


Related pages


hide excel cellsinsert row excel 2007vba open file for inputunload me vba excelsample pivot tableshow to insert a pivot table in excel 2013example vlookup formulaexcel lookup functionvba activexsql ddl statementsexcel vba display userformexcel vba if multiple conditionsauto fit row heightexcel trim commandexcel logic formulashow to countif in excelhow to capture data from userform into excel worksheetcreating a dashboard in excel 2007project charter word templatems excel formula with examplevlookup argumentsword userformcreating check boxes in excelexcel macro open excel fileworkbooks.close vbaexcel unlock sheetmicrosoft excel graph tutorialsumif exceexcel vba clear rangeisblank formulaexcel reports and dashboardswhat is sumifif cell contains text then excelwrite excel macroqlikview beginners guidesort in ascending order excelexcel formula sumifsql query interview questions and answers for freshers pdfexcel 3d surface plotcombine worksheets into one worksheetremoving duplicate rows in excelmerge multiple excel files into one sheet vbaexcel vba forms examplesbasics of testing interview questions and answersvba range variablemost useful programshow to merge three columns in excelproject plan template word docexcel 2010 unhide allhow to sumif in exceldelete blank rows in excelworkbook save vbamerging excelhow to remove blank rows excelexcel formula to copy cell valuehow to protect excel worksheetrun sql in excelhow to remove a drop down box in excelvba file nameexcel vba worksheet nameoffset vlookupgantt chart in excel 2007add the developer tab to the ribbon wordcreate userform vbaunderstanding macros in excelexcel charts tutorialexcel macro debugaverage vbavba move filehow to highlight columns in exceltask log template excelarray vbamacros excel tutorialvba sortingexcel macro delete rowtrim excel functionsql telephonic interview questionsexcel vba unselectschedule excel templates