ABSTRACT

To call a sub, you write its name followed by any arguments that are passed into it. In this example, we are not passing any arguments.

The two subs are getRange and countValidCells (Listings 9.1 and 9.2). The purpose ofthe getRange procedure is to enable the user to enter a cell range, and the procedure would select the cell range on the worksheet. It does this by using a range variable, Rng, stored from the InputBox method of the Application object. The IfRng Is Nothing Then statement checks to see that the user has selected a range. Ifnot, then an "Operation Cancelled" message appears, otherwise the selected range is highlighted. The next statement will call the CountValidCells sub. This works by creating two variables: an integer variable to store the number ofnon-blank cells, and a string variable called strCount to store a string version of this variable so that it can be formatted for use with a MsgBox function. The statement: myCount = Application.CountA(Selection) uses the CountA method for counting all non-blank cells in the range, and the statement: strCount = Str(myCount) converts the integer variable to a string variable for use in the MsgBox.