30.04.2017 Views

4523756273

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

220<br />

Part III: Programming Concepts<br />

Figure 14-3:<br />

Excel<br />

doesn’t like<br />

it if you try<br />

to copy a<br />

multiple<br />

selection.<br />

The following macro demonstrates how to determine whether the user made<br />

a multiple selection so your macro can take appropriate action:<br />

Sub MultipleSelection()<br />

If Selection.Areas.Count > 1 Then<br />

MsgBox “Multiple selections not allowed.”<br />

Exit Sub<br />

End If<br />

‘ ... [Other statements go here]<br />

End Sub<br />

This example uses the Areas method, which returns a collection of all objects<br />

in the selection. The Count property returns the number of objects in the<br />

collection.<br />

Changing Excel Settings<br />

Some of the most useful macros are simple procedures that change one or<br />

more of Excel’s settings. For example, if you find yourself making frequent<br />

trips to the Excel Options dialog box to change a setting, that’s a good candidate<br />

for a simple time-saving macro.<br />

This section presents two examples that show you how to change settings in<br />

Excel. You can apply the general principles demonstrated by these examples<br />

to other operations that change settings.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!