Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-04-28
2
Medium Priority
?
3,318 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
New style of hardware planning for Microsoft Exchange server.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

704 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