Trouble Using a Named Range with Rows( )

Space Norman 20 Reputation points
2025-11-29T04:18:53.24+00:00

Hello All! I'm a Visual Basic "newbie" - just 2 days into my Visual Basic experience.

I have a need to hide and/or unhide a range of rows at the bottom of a filtered table. The following subroutines using specific Row references works great - except that the range of rows changes dynamically as rows are added / deleted from the data.

I've created a "Named Range" called xHidden using the Name Manager. I've confirmed that the range of rows change appropriately as rows are added or deleted from the data (by looking at range defined in the Name Manager before and/or after adding and/or deleting rows from the data.

Both routines execute as desire using the specific row references shown in the code snippets below. However, replaceing the specific row reference with named range identifier "xHidden" immediately errors out. I've tried it as Rows("xHidden").Select as well as Rows(xHidden).Select which both fail. What am I missing?

Sub HideHidden()

Sheets("Transaction Log").Select

Rows("$143:$159").Select

Selection.EntireRow.Hidden = True

End Sub

Sub ShowHidden()

Sheets("Transaction Log").Select

Rows("$143:$159").Select

Selection.EntireRow.Hidden = False

Range("A1").Select

End Sub

Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Answer accepted by question author
  1. Q&A Assist
    2025-11-29T04:20:02.9133333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To use a named range like xHidden with the Rows() method in your VBA code, you need to reference the named range correctly. The Rows() method does not accept named ranges directly as a string. Instead, you can use the Range() method to refer to the named range. Here’s how you can modify your subroutines:

    Sub HideHidden()
        Sheets("Transaction Log").Select
        Range("xHidden").EntireRow.Hidden = True
    End Sub
    
    Sub ShowHidden()
        Sheets("Transaction Log").Select
        Range("xHidden").EntireRow.Hidden = False
        Range("A1").Select
    End Sub
    

    In this code, Range("xHidden") will correctly reference the named range you created, and then you can set the EntireRow.Hidden property as desired. This should resolve the errors you were encountering when trying to use the named range with Rows().


    References:


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.