XL: Counting Cells That Contain Formulas, Text, or NumbersLast reviewed: February 2, 1998Article ID: Q104412 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, you can count the number of cells in a worksheet that contain formulas, text, or numbers, by using the Go To Special dialog box (versions 5.0 and later) or the Select Special dialog box (versions 4.0 and earlier) to select the cells and then running a macro that counts the number of selected cells.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.asp Selecting the CellsFollow the appropriate procedure below to select formulas, text, or numbers. Microsoft Excel Versions 5.0 and Later:
Running a Macro to Count the Selected CellsVisual Basic Procedure for Versions 5.0 and Later: The following procedure counts the number of cells in the selection and displays the result in a message box:
Sub Count_Selection() Dim cell As Object Dim count As Integer count = 0 For Each cell In Selection count = count + 1 Next cell MsgBox count & " item(s) selected" End SubMicrosoft Excel Macro for Versions 4.0 and Earlier: The following macro counts the number of cells selected and displays the result in an Alert dialog box:
A1: Count_Selection A2: Count=0 A3: =FOR.CELL("Current") A4: Count=Count+1 A5: =NEXT() A6: =ALERT(Count&" item(s) selected") A7: =RETURN()Following is an explanation of the preceding macro:
A1: Contains the name of the macro. A2: Initializes Count to 0. A3: The FOR.CELL() allows the macro to loop through each selected cell. A4: Adds 1 to the current count. A5: Completes the FOR.CELL() loop. A6: Displays an Alert Box with the count results. A7: Ends the macro. REFERENCES"User's Guide 2," version 4.0, pages 203-204 "User's Guide," version 3.0, pages 79-80
|
Additional query words: 4.00 4.00a 5.00 7.00 8.00 XL98 XL97 XL7 XL5 XL4 XL3
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |