Solved

How to create a VBA to hide/unhide rows based on a cell value?

Posted on 2014-04-28
2
3,078 Views
Last Modified: 2014-04-28
I have a questionnaire that may have additional questions depending on the answer.  For example, if the answer for question 1 is “Yes”, then I want the row that contains question 1.1 to unhide.  If the answer is “No” or “Blank”, then I want to make sure the row that contains question 1.1 is hidden.  Please see the attached sample file.
Sample-File.xlsx
0
Comment
Question by:kbay808
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 40028795
You would need a macro to do this. To reduce macro coding and increase flexibility it could be more convenient to enter the response for display and the row to display in predefined columns. I have attached a sample file with the following code

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then
    For Each cel In Target
        Call Worksheet_Change(cel)
    Next cel
End If
If Target.Column = 3 Then
    If LCase(Target.Value) = LCase(Target.Offset(, 2)) Then
        Cells(Target.Offset(, 3), 1).EntireRow.Hidden = False
    Else
        Cells(Target.Offset(, 3), 1).EntireRow.Hidden = True
    End If
End If
End Sub
Sample-File.xlsm
0
 

Author Closing Comment

by:kbay808
ID: 40028805
Great Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to read BOM (Byte Order Mark) from csv file. 4 35
Office 2016 Excel Issue 4 25
Microsoft Edge, Outlook OWA 7 38
Access Excel export not behaving 2 24
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now