Coming soon - Get a detailed view of why an account is flagged as spam!
view details
6
[VBA] How to auto hide cells based on multiple cell values
Post Flair (click to view more posts with a particular flair)
Author Summary
PrinceHans is in VBA
Post Body

EDIT: Solution in the comments.

Hello all, I really hate to ask this but I've been looking at this all day and am not fluent in VBA and all my attempts result in having to force end Excel and a Macro-Enabled file that I cannot interact with in any way. I need some assistance!

What I'm looking at is trying to hide specific rows based on the values present in two other cells. Hopefully there should be an image attached within this post to accompany the following explanation.

Rundown: Cell B3 has two answers "Yes" or "No" chosen from a drop down list. Cell B4 has 3 options from a drop down list (different types of property). If "Yes" is chosen in B3 then I don't want any row hiding to be performed, everything is fine as is. If "No" is chosen in B3 then I want specific groups of rows to be hidden based on the answer chosen in cell B4, with each property type having it's own group of rows to be hidden. I am uncertain how to accomplish this.

From my research I came across a tutorial that seemed to teach what I wanted - but when I tried applying my own ranges and functions it does not work and my worksheet becomes 'inoperable'. I'll save a Macro-Enabled copy to my computer but upon trying to close the document the software freezes and I have to force end it. Additionally after hitting save on my VBA screen I am unable to interact with anything in the workbook at all. Below is my current attempts at VBA language for this. I know it probably looks like a bastardization of VBA but this was my most recent attempt with some chunks cut out.

Thank you to any of you who have taken the time to read this and attempt to help me (I promise I will try to understand the things you say!) and please let me know if there's any other information or details I can provide to help figuring out a solution to this. Any and all help is immensely appreciated! :)

.

Private Sub Worksheet_Calculate()

Dim Years, Property As Range

Set Years = Range("B3")

Set Property = Range("B4")

Select Case Years

Case Is = "Yes": Rows("16:53").EntireRow.Hidden = False 'All years are shown

Case Is = "No":Rows("16:20").EntireRow.Hidden = True

End Select

Select Case Property

Case Is = "Residental Rental - 27.5"Rows("16:22").EntireRow.Hidden = True

Case Is = "Nonresidential Real - 31.5"Rows("16:20").EntireRow.Hidden=True

Case Is = "Nonresidential Real - 39"Rows("16:53").EntireRow.Hidden=True

End Select

End Sub

https://preview.redd.it/ipm4juxlqb241.png?width=1661&format=png&auto=webp&s=7554f950202ad5166c137daf59dd2c3cf9607604

Author
Account Strength
100%
Account Age
11 years
Verified Email
Yes
Verified Flair
No
Total Karma
46,620
Link Karma
3,673
Comment Karma
42,947
Profile updated: 1 day ago
Posts updated: 10 months ago

Subreddit

Post Details

Location
We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago