Skip to Main Content
Microsoft Excel 365 Bible
book

Microsoft Excel 365 Bible

by Michael Alexander, Dick Kusleika
March 2022
Beginner to intermediate content levelBeginner to intermediate
1072 pages
28h 16m
English
Wiley
Content preview from Microsoft Excel 365 Bible

CHAPTER 41Creating UserForms

You can't use Excel very long without being exposed to dialog boxes. Excel, like most Windows programs, uses dialog boxes to obtain information, clarify commands, and display messages. If you develop VBA macros, you can create your own dialog boxes that work very much like those that are built into Excel. These dialog boxes are known as UserForms.

Understanding Why to Create UserForms

Some macros that you create behave the same every time that you execute them. For example, you may develop a macro that enters a list of your sales regions into a worksheet range. This macro always produces the same result and requires no additional user input. You may develop other macros, however, that perform differently under different circumstances or that offer options for the user. In such cases, the macro may benefit from a custom dialog box.

The following is an example of a simple macro that makes each cell in the selected range uppercase (but skips cells that have a formula). The procedure uses VBA's built-in StrConv function:

Sub ChangeCase()
  For Each cell In Selection
    If Not cell.HasFormula Then
      cell.Value = StrConv(cell.Value, vbUpperCase)
    End If
  Next Cell
End Sub

This macro is useful, but it can be improved. For example, the macro ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel 2019 Bible

Excel 2019 Bible

Michael Alexander, Richard Kusleika, John Walkenbach

Publisher Resources

ISBN: 9781119835103Purchase Link