VBA Code - Hide / Unhide Rows based on Entity Type

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

Not had to write a code like this so have taken a stab in the dark but it's not liking it. Can anyone see where I am going wrong please? When I try to run it, the error highlights the second row of code (If Not Intersect...)
The "Entity_Type" is located in cell D8. The "Entity Type" is selected on another sheet by a drop down and just transferred over to this sheet.
I'm trying to hide/unhide rows depending on whether the Entity Type is Company or not.

Thank you!

Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Intersect(Target, Range("Entity_Type")) Is Nothing Then


If Target.Cells.CountLarge > 1 Then Exit Sub
Select Case Target.Value


    Case Is <> "Company"
        Range("26:29:,52:88").EntireRow.Hidden = True
    Case "Company"
        Range("26:29:,52:88").EntireRow.Hidden = False
     
   End Select
   End If


End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Maybe this:
Code:
[FONT=lucida console][COLOR=Royalblue]Private[/COLOR] [COLOR=Royalblue]Sub[/COLOR] Worksheet_Change([COLOR=Royalblue]ByVal[/COLOR] Target [COLOR=Royalblue]As[/COLOR] Range)


[COLOR=Royalblue]If[/COLOR] [COLOR=Royalblue]Not[/COLOR] Intersect(Target, Range([COLOR=brown]"D8"[/COLOR])) [COLOR=Royalblue]Is[/COLOR] [COLOR=Royalblue]Nothing[/COLOR] [COLOR=Royalblue]Then[/COLOR]

[COLOR=Royalblue]If[/COLOR] Target.Cells.CountLarge > [COLOR=crimson]1[/COLOR] [COLOR=Royalblue]Then[/COLOR] [COLOR=Royalblue]Exit[/COLOR] [COLOR=Royalblue]Sub[/COLOR]

    Range([COLOR=brown]"26:29:,52:88"[/COLOR]).EntireRow.Hidden = Target.Value <> [COLOR=brown]"Company"[/COLOR]
 
[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]If[/COLOR]


[COLOR=Royalblue]End[/COLOR] [COLOR=Royalblue]Sub[/COLOR][/FONT]
 
Upvote 0
Thanks. Although now it's showing the error on line;

Range("26:29:,52:88").EntireRow.Hidden = Target.Value <> "Company"
 
Upvote 0
Sorry, replace with this:
Code:
Range("26:29, 52:88").EntireRow.Hidden = Target.Value <> "Company"
 
Upvote 0
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,752
Messages
6,180,743
Members
452,996
Latest member
nelsonsix66

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