You are on page 1of 5

14/06/12

Create an Excel UserForm


Search Contextures Sites

Search

Cubilis Channel Manager Manage all your bookingsites on a single interface, no over-bookings! www.cubilis.com PowerBasic vs VisualBasic Faster. No Run-Times. No Bloat! CGI, Macros, ASM, Reg Expressions Wgezellen, Load Cells, Kraftaufnehmer, Wgetechnik, Weighing Sensors, Weight Indicators
www.powerbasic.com

www.gbuettner.de

Create an Excel UserForm


Convert PDF to Word
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.
Set up the the worksheet Create an Excel UserForm Name the Excel UserForm Add a Textbox to the Excel UserForm Add a Label to theExcel UserForm Add remaining textboxes and labels Add buttons to the Excel UserForm Add code to the buttons Test the Excel UserForm Create a button to open the Excel UserForm Finish the workbook

with ABBYY PDF Transformer - PDF conversion and PDF creation tool
pdftransformer.abbyy.com

vLookup for Procurement


Learn how use MS Excel functions, including vLookup in this article!
www.NextLevelPurchasing.com

PDF Writer for VB


Create, display, print, edit, merge Royalty-free distribution. Try now!
www.synactis.com

Download the zipped sample Excel UserForm file See also, Excel UserForm video (video is in 3 parts) and Excel UserForm with Combo Boxes .

To make it easier for users to enter data in a workbook, you can create an Excel UserForm. In this example, a parts inventory is stored on a hidden worksheet. Users enter data by opening the Excel UserForm, filling in the boxes, and clicking a button. To view the steps in a short video, click here (video is in 3 parts).

Set up the worksheet


In this example, a parts inventory is stored on a hidden worksheet. 1. 2. 3. 4. 5. Open a new workbook Double-click on the sheet tab for Sheet1 Type: PartsData Press the Enter key In cells A1:D1, enter the headings for the parts inventory database, as shown at right. 6. Choose File | Save, and save the workbook. In this example, the file has been named PartsLocDB.xls.

A B C D 1 PartID Location Date Qty Store 2 12345 3/3/2004 87 001 3

Create an Excel UserForm


Excel UserForms are created in the Visual Basic Editor. 1. To open the Visual Basic Editor, hold the Alt key, and press the F11 key 2. Choose View | Project Explorer, to see a list of projects. (Usually, this is displayed at the left side of the VBE window.) 3. In the Project Explorer, select the PartLocDB project.
contextures.com/xlUserForm01.html 1/5

14/06/12

Create an Excel UserForm

4. From the menu bar, choose Insert | UserForm 5. A blank UserForm appears, and the ToolBox should open. (If the ToolBox doesn't appear, choose View | Toolbox)

Name the Excel UserForm


1. To open the Properties window, press the F4 key 2. In the Properties window, double-click on the Name -UserForm1, at the top right of the window. 3. Type: frmPartLoc and press the Enter key 4. The form name will change in the Project Explorer, but the form still shows UserForm1 in its title bar. 5. In the Properties window, double-click on the Caption property-- UserForm1. 6. Type: Parts Inventory and press the Enter key 7. The title bar will display the new caption.

Add a Textbox to the Excel UserForm


The objects on an Excel UserForm, such as buttons, and textboxes, are called controls. To allow users to enter data, you can add textbox controls to the form, with label controls to describe them. 1. In the Toolbox, click on the TextBox button. 2. On the UserForm, click near the top centre, to add a standard sized textbox. 3. With the new textbox selected, double-click on the Name property in the Properties window. 4. Type: txtPart and press the Enter key 5. Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox.
Ads by Google Excel Dashboards Download Excel Excel Excel VBA Worksheet

Add a Label to the Excel UserForm


To help users enter data, you can add label controls to describe the textboxes, or to display instructions. 1. In the Toolbox, click on the Label button. 2. On the UserForm, click to the left of the textbox, to add a standard sized label. 3. With the new label selected, double-click on the Caption property in the Properties window. 4. Type: Part and press the Enter key 5. If necessary, you can resize the label, so it doesn't cover the textbox -- point to the handle on its right border, and drag to the left. 6. Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox.

To view the steps in a short video, click


here

(video is in 3 parts).

Add remaining textboxes and labels


Repeat the above steps to add: a textbox named txtLoc, with a label Location a textbox named txtDate, with a label Date
contextures.com/xlUserForm01.html 2/5

14/06/12

Create an Excel UserForm

a textbox named txtQty, with a label Quantity

If the textboxes are not aligned, you can align them:


1. 2. 3. 4. Click on the first textbox Hold the Ctrl key, and click on the remaining textboxes Choose Format | Align | Lefts Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox.

Add Buttons to the Excel UserForm


To allow users to perform an action, you can add command buttons to the user form. This form has a button to add data to the database, and a button to close the form. 1. In the Toolbox, click on the CommandButton button. 2. On the UserForm, click at the bottom left, to add a standard sized CommandButton. 3. With the new CommandButton selected, double-click on the Name property in the Properties window. 4. Type: cmdAdd and press the Enter key 5. With the new CommandButton selected, double-click on the Caption property in the Properties window. 6. Type: Add this part and press the Enter key 7. Click on an empty part of the Excel UserForm, to select the UserForm and to display the Toolbox. 8. Repeat the above steps to add a CommandButton named cmdClose, with a label Close 9. If required, you can reposition the buttons by dragging them to a new location on the UserForm.

To view the steps in a short video, click


here

(video is in 3 parts).

Add code to the buttons


To make the Excel UserForm buttons perform an action, you create code that runs when the button is clicked. Add code to the cmdAdd button 1. 2. 3. 4. Select the cmdAdd button On the Menu bar, choose View | Code. This creates a procedure, where you can add your code. Where the cursor is flashing, enter the following code:
PiaeSbcdd_lc( rvt u mAdCik) Dmio A Ln i Rw s og Dmw A Wrset i s s okhe Stw =Wrset(Prsaa) e s okhes"atDt" 'idfrtepyrwi dtbs fn is mt o n aaae io =w.el.idWa:"" SacOdr=los _ Rw sClsFn(ht=*, erhre:xRw, SacDrcin=lrvos LoI:xVle)Rw+1 erhieto:xPeiu, okn=laus.o 'hc frapr nme cek o at ubr I Ti(ettatVle =" Te f rmM.xPr.au) " hn M.xPr.eFcs ettatStou Mgo "laeetrapr nme" sBx Pes ne at ubr Ei Sb xt u EdI n f 'oytedt t tedtbs cp h aa o h aaae w.el(Rw 1.au =M.xPr.au sClsio, )Vle ettatVle w.el(Rw 2.au =M.xLcVle sClsio, )Vle etto.au w.el(Rw 3.au =M.xDt.au sClsio, )Vle ettaeVle w.el(Rw 4.au =M.xQyVle sClsio, )Vle ettt.au 'la tedt cer h aa M.xPr.au =" ettatVle " M.xLcVle=" etto.au " M.xDt.au =" ettaeVle "

contextures.com/xlUserForm01.html

3/5

14/06/12
M.xQyVle=" ettt.au " M.xPr.eFcs ettatStou EdSb n u

Create an Excel UserForm

5. On the Menu bar, choose View | Object, to return to the UserForm.

Add code to the cmdClose button


1. Select the cmdClose button 2. On the Menu bar, choose View | Code. 3. Where the cursor is flashing, enter the following code:
PiaeSbcdls_lc( rvt u mCoeCik) Ula M nod e EdSb n u

View the steps in a


short Excel UserForm video

(video is in 3 parts).

4. On the Menu bar, choose View | Object, to return to the UserForm. To allow users to close the form by pressing the Esc key: 1. Select the cmdClose button 2. In the Properties window, change the Cancel property to True

Ads by Google Excel Excel 2003 Excel VBA Excel to Text

Test the Excel UserForm


To test the form, you can run it from the VBE. 1. Click on an empty part of the UserForm, to select the UserForm and to display the Toolbox. 2. On the Menu bar, choose Run | Run Sub/UserForm. 3. In the Part textbox, type: 12345 4. Press the tab key to move to the next textbox. 5. When the textboxes have been filled in, click the 'Add this part' button. 6. Click the 'Close form' button, to return to the VBE. If the tab order was incorrect (e.g. when you pressed the tab key you moved to the wrong textbox or button), you can change it 1. Right-click on an empty part of the UserForm 2. Choose Tab Order 3. Select a control in the list, and click the Move Up or Move Down button 4. Click OK

Create a Button to open the Excel UserForm


To make it easy for users to open the UserForm, you can add a button to a worksheet. Switch to Excel, and activate the PartLocDB.xls workbook Double-click on the sheet tab for Sheet2 Type: Parts Data Entry Press the Enter key On the Drawing toolbar, click on the Rectangle tool In the centre of the worksheet, draw a rectangle, and format as desired. With the rectangle selected, type: Click here to add Part Information 8. Right-click on the rectangle border, and choose 'Assign Macro' 9. Click the New button 10. Where the cursor is flashing, type: frmPartLoc.Show Note: If you are using Excel 2000, or later version, and want users to be able to do other things while the form is open, change the above line to: frmPartLoc.Show False
contextures.com/xlUserForm01.html 4/5

1. 2. 3. 4. 5. 6. 7.

14/06/12

Create an Excel UserForm

To prevent users from closing the form by clicking the X button: 1. Right-click on an empty part of the UserForm 2. Choose View | Code 3. Scroll to the bottom of the existing code, and enter the following code:
PiaeSbUeFr_urCoeCne A Itgr _ rvt u sromQeyls(acl s nee, CoeoeA Itgr lsMd s nee) I Coeoe=vFrCnrleuTe f lsMd bomotoMn hn Cne =Tu acl re Mgo "laeuetebto! sBx Pes s h utn" EdI n f EdSb n u

4. On the Menu bar, choose View | Object, to return to the UserForm.

Finish the Workbook


To finish the workbook, you can hide the sheet that contains the database. 1. Switch to Excel, and activate the PartLocDB.xls workbook 2. Select the PartsData sheet. 3. From the menu bar, choose Format | Sheet | Hide 4. Delete all other sheets, except Parts Data Entry 5. Click the Click here to add Part Information button, and enter your data into the database. 6. Close and save the workbook Download the sample Excel UserForm file Download the sample file with an enhanced Excel UserForm, with comboboxes See also, Excel UserForm video (video is in 3 parts) and Excel UserForm with Combo Boxes .

Home

Excel Tips

Excel Files

The Excel Store

Blog

Contact

Privacy Policy

Contextures Inc., Copyright 2012 All rights reserved.


Debra Dalgleish

Last updated: January 11, 2012 9:09 PM

contextures.com/xlUserForm01.html

5/5

You might also like