How to Hide / Unhide Specific Name Range using VBA

< Back to Search results

 Category: [Excel]  Demo Available 

How to Hide / Unhide Specific Name Range using VBA




The user has the below VBA works properly to hide/unhide rows 2:4

Sub Trial1()
If Rows("2:4").Hidden = True Then
Selection.EntireRow.Hidden = False
Selection.EntireRow.Hidden = True
End If
Application.GoTo Range("A1"), True
End Sub

Supposedly the user named rows 2:4 to some Range Name, say Range Name “Magdoulin”
How could the user rewrite the code to hide/unhide this particular range name in this case?

The user intends to build a sheet which would have very dynamic rows interred from time to time and writing the code depending on numbering the rows themselves would be a disaster in this case.






Sub Trial2()
' Toggle to Hide / Unhide Range("Magdoulin")
With Rows(Range("Magdoulin").Address)
  .EntireRow.Hidden = Not .EntireRow.Hidden
End With
Application.GoTo Range("A1"), True
End Sub

Hope this will help


Obtained from the OzGrid Help Forum.

Solution provided by Carim.


See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets


See also:

How to hide and unhide with checkboxes - multiple checkboxes do multiple different things
How to reference text in cell to unhide worksheet
How to unhide worksheets identified by specific cells in main sheet
How to hide/unhide rows


Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.




stars (0 Reviews)