Select Page

Excel VBA UserForms #2

Create a UserForm with 2 option buttons:  1 Sort by Employee ID or 2 Sort by Name.

Part one, create the UserForm and give it buttons.

  1. First, bring up the VBA UserForm editor (F11), and add a new UserForm  using the dropdown in the upper left of the screen.UserForm Dropdown
  2. Rename the UserForm to “sortform” and change the caption to “Choose sort option”:Screen Shot 02-12-16 at 02.51 AM
  3. Add two Option Buttons (or as many as you need for your form), and two Command Buttons to your UserForm using the toolbox:Screen Shot 02-12-16 at 02.57 AM
  4. Next, (name) and Caption your command buttons (sort and cancel, respectively).
  5. Then let’s program the Cancel button, using the .hide command from UserForms #1 video.Screen Shot 02-20-16 at 09.13 PM
  6. Now we’ll edit the caption on the Option buttons, naming one Emp Id, and the other Name.

Part Two, recording a macro

  1. Click the Record macro button, hit ok on the window that pops up, and select your range of cells you wish to include for sortingCell range selection
  2. Select Data on the menu bar and hit the sort button, then select Emp Id in the Sort by dropdown box and hit ok. Repeat for the Name column.Sort by selection box
  3. Bring up the VBA window with alt-F11


Part three, use the macro to code the buttons

  1. Go to the most recent module and copy the selection as shownCode Selection
  2. Select the sortform and double-click the sort button to paste in the codeCode insert
  3. Add in the following code above your pasted code:
    [snippet id=”52″]
  4. Add in this code, or for step-by-step instructions and complete explanation, please watch the full video below!
    [snippet id=”53″]



You Might Also Like

Create Sheets For Each User From Column A

Create Sheets For Each User From Column A

Sometimes in Excel, we need to automate simple tasks, like to create sheets automatically for each item in a range. If you just had a few worksheet tabs that needed to be created, it wouldn't be a big deal, but what if you had to create 100 different worksheet tabs?!...

How To Add A Date Picker Calendar in Excel VBA

How To Add A Date Picker Calendar in Excel VBA

Date Picker Calendar in Excel VBA Oftentimes, users want to click a button and select a date. This is no different for Excel developers. Check out this ActiveX control by Microsoft that allows users to do just that. It's a little old school looking, but actually has...


Forgot Password?

Join Us

Discover the Secrets of Excel Your Coworkers Don't Want You To Know and Your Boss Will Love You For...

Free video training will be sent to your email

You have Successfully Subscribed!

    Your Cart
    Your cart is emptyReturn to Shop