Solved

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

Posted on 2014-04-28
2
3,061 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

708 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

17 Experts available now in Live!

Get 1:1 Help Now