Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Skipping Hidden Rows in a Macro.

Skipping Hidden Rows in a Macro

Written by Allen Wyatt (last updated March 14, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


2

When using a worksheet, it is not uncommon to hide rows that contain data you don't want displayed at the current time. If you have written a macro that processes the data in the worksheet, you may have wondered how to skip over and not process the rows that you have marked as hidden.

The way you accomplish this is to check the Hidden property of each row. If the property is True, then the row is hidden; if False, then row is visible.

As an example of how this works, assume that you have a worksheet that you use to track clients. Some of these clients are considered active, and others inactive. To mark a client as inactive, you hide the row containing the client. At some point, you want to number the active clients, and you want to do it using a macro. The following macro will do the trick for you:

Sub NumberClients()
    Dim c As Range
    Dim j As Integer

    If Selection.Columns.Count > 1 Then
        MsgBox "Only select the cells you want numbered"
        Exit Sub
    End If

    j = 0
    For Each c In Selection
        If Not c.Rows.Hidden Then
            j = j + 1
            c.Value = j
        Else
            c.Clear
        End If
    Next c
End Sub

To use the macro, simply select the cells in which the numbering will be done. The macro checks, first of all, to make sure you have only selected cells in a single column. Then, it steps through each cell in the selected range. If the row containing the cell is not hidden, then the counter (j) is incremented and stored in the cell. If the row containing the cell is hidden, then the contents of the cell are cleared. The key to this macro is the If ... End If structure that tests the value of the Hidden attribute.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2286) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Skipping Hidden Rows in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Understanding Font Styles

Fonts, by default, come with one or more styles that define variations of how that font is displayed in your document. ...

Discover More

Automatically Updating Charts for Additional Data

Add information to the data on which a chart is based, and you may find out that the information is excluded from the ...

Discover More

Backing Up Label Layouts

Once you create a custom label layout it is a good idea to backup the layout on a different hard drive in the event of a ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (menu)

Conditionally Displaying a Message Box

You can, from within your macros, easily display a message box containing a message of your choice. If you want to ...

Discover More

Determining If a Number is Odd or Even

If you need to know whether a particular value is odd or even, you can use this simple formula. Designed to be used in a ...

Discover More

Counting Shaded Cells

Ever want to know how many cells in a worksheet (or a selection) are shaded in some way? You can create a handy little ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 1 + 1?

2020-06-17 02:40:42

Alan Elston

Hi Anshu,
I have never heard of any simple way to do that. So you would have to modify any macros you have to check for the condition to ignore that row. So you would need something like, pseudo code:
If Range(“A” & Rw & “”).Value = "TC" Then
' Do Nothing
Else
' Do what ever should normally be done
End If

Alan Elston
(DocAElstein)


2020-06-15 15:00:56

Anshu Kumar

Sir,
I've similar but different Problem.

I have a sheet in which I want to ignore the entire row based on a cell value, but still it must be visible.
Means completely ignored row but visible.

"Ignore the entire row" means if I copy, paste or apply sum , counta etc formula, then the row is skipped completely.

For example,
If I put "TC" in cell A4, the entire row 4 behaves as if it does not exist there, means it does not participate in any excel processing.
The only work of this row is to be seen.


Is it possible to do so??


Thanks!


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.