VBA if function for hiding/unhiding rows

ifu06416

Board Regular
Joined
Sep 5, 2011
Messages
56
Office Version
  1. 365
I have a table with a series of hyperlinks that I am using to trigger a macro for hiding/unhiding certain rows.

Cell C3 contains the main menu, when it is clicked a collection of sub menus headings become unhidden in rows 6, 78, 155, 177 & 354.

In turn, when each of the sub menu headings are clicked more rows become unhidden with sub menu content. For example; clicking the sub menu heading in B6 unhides the sub menu content in rows 7:10.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Address = "$C$3" Then
Call CMC_WIPBreakdown
End If

If Target.Range.Address = "$B$6" Then
Call CMC_CaseProgress
End If


Sub CMC_WIPBreakdown()
Range("6:6").Select
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
End Sub

Sub CMC_CaseProgress()
Range("7:10").Select
If Selection.EntireRow.Hidden = True Then
Selection.EntireRow.Hidden = False
Else
Selection.EntireRow.Hidden = True
End If
End Sub

The issue I am having is that when it comes to hiding the rows again they have to be hidden in order, ie the sub menu contents from each of the sub menus (rows 7:10) has to be hidden (by clicking b6) before clicking c3 to hide the sub menu itself.

I was looking for a way so that when c3 is clicked, if the sub menu heading (row 6) and their contents (7:10) are unhidden then both are rehidden. If c3 is clicked and they are hidden then only the sub menus headings are unhidden.

Regards,

John.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
Something like
Code:
[LEFT][COLOR=#333333][FONT=Verdana]Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)[/FONT][/COLOR]
[COLOR=#333333][FONT=Verdana]If Target.Range.Address = "$C$3" Then[/FONT][/COLOR][/LEFT]
   if (Range("6:6").entirerow.hidden=false and Range("7:10").entirerow.hidden=false) then
     Range("6:10").entirerow.hidden=true
else
 range("6:6").entirerow.hidden=false
Range("7:10").entirerow.hidden=true
End if


[LEFT][COLOR=#333333][FONT=Verdana]End If
End sub[/FONT][/COLOR][/LEFT]
 
Upvote 0
Ah, much better. That looks a lot more user friendly.

Thanks for your help.

John.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top