Solved

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

Posted on 2014-04-28
2
3,204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

729 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