O'Reilly logo

Excel VBA Programming For Dummies, 5th Edition by John Walkenbach, Michael Alexander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16

UserForm Basics

IN THIS CHAPTER

Bullet Finding out when to use UserForms

Bullet Understanding UserForm objects

Bullet Displaying a UserForm

Bullet Creating a UserForm that works with a useful macro

A UserForm is useful if your VBA macro needs to pause and get some information from a user. For example, your macro may have some options that can be specified in a UserForm. If only a few pieces of information are required (for example, a Yes/No answer or a text string), one of the techniques in Chapter 15 may do the job. But if you need to obtain more information, you must create a UserForm. That’s what this chapter is all about.

Knowing When to Use a UserForm

This section describes a situation in which a UserForm is useful. The following macro changes the text in each cell in the selection to uppercase letters. It does this by using the VBA built-in UCase function.

Sub ChangeCase()

Dim WorkRange As Range, cell As Range

' Exit if a range is not selected

If TypeName(Selection) <> "Range" Then Exit Sub

' Process only text cells, no formulas

On Error Resume Next

Set WorkRange = Selection.SpecialCells ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required