Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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…

696 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