Need help to hide/show excel rows based on value in a cell, but allow for moving rows around later












0















In Row 4 I ask a question and D4 will contain the answer of either Yes or No.



If the answer is Yes in D4, I want hidden rows 5 and 5 to appear with follow-up questions. This is working for me:



If Range("D4").Value = "No" Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("D4").Value = "Yes" Then
Rows("5:6").EntireRow.Hidden = False


In Column A I identify the initial questions (like in row 4) as "Tiered Questions" and the subsequent questions (like rows 5 and 6) are labeled "Follow-up Q".



Is there a way to do this without manually updating every row? Also, I need to allow for adding/removing rows above which would impact which rows will hide/unhide. Thanks.










share|improve this question























  • Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

    – Prasanna
    Apr 7 '16 at 2:34
















0















In Row 4 I ask a question and D4 will contain the answer of either Yes or No.



If the answer is Yes in D4, I want hidden rows 5 and 5 to appear with follow-up questions. This is working for me:



If Range("D4").Value = "No" Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("D4").Value = "Yes" Then
Rows("5:6").EntireRow.Hidden = False


In Column A I identify the initial questions (like in row 4) as "Tiered Questions" and the subsequent questions (like rows 5 and 6) are labeled "Follow-up Q".



Is there a way to do this without manually updating every row? Also, I need to allow for adding/removing rows above which would impact which rows will hide/unhide. Thanks.










share|improve this question























  • Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

    – Prasanna
    Apr 7 '16 at 2:34














0












0








0








In Row 4 I ask a question and D4 will contain the answer of either Yes or No.



If the answer is Yes in D4, I want hidden rows 5 and 5 to appear with follow-up questions. This is working for me:



If Range("D4").Value = "No" Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("D4").Value = "Yes" Then
Rows("5:6").EntireRow.Hidden = False


In Column A I identify the initial questions (like in row 4) as "Tiered Questions" and the subsequent questions (like rows 5 and 6) are labeled "Follow-up Q".



Is there a way to do this without manually updating every row? Also, I need to allow for adding/removing rows above which would impact which rows will hide/unhide. Thanks.










share|improve this question














In Row 4 I ask a question and D4 will contain the answer of either Yes or No.



If the answer is Yes in D4, I want hidden rows 5 and 5 to appear with follow-up questions. This is working for me:



If Range("D4").Value = "No" Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Range("D4").Value = "Yes" Then
Rows("5:6").EntireRow.Hidden = False


In Column A I identify the initial questions (like in row 4) as "Tiered Questions" and the subsequent questions (like rows 5 and 6) are labeled "Follow-up Q".



Is there a way to do this without manually updating every row? Also, I need to allow for adding/removing rows above which would impact which rows will hide/unhide. Thanks.







microsoft-excel macros conditional-statements






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 6 '16 at 20:32









JessicaJessica

111




111













  • Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

    – Prasanna
    Apr 7 '16 at 2:34



















  • Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

    – Prasanna
    Apr 7 '16 at 2:34

















Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

– Prasanna
Apr 7 '16 at 2:34





Can you post an image of what you are asking about? I do not understand this part of your question Is there a way to do this without manually updating every row

– Prasanna
Apr 7 '16 at 2:34










2 Answers
2






active

oldest

votes


















0














I'm not sure exactly what you mean by "manually updating every row" but if you put your code into a Worksheet_Change sub into your worksheet object (not a module) then it will run automatically every time cell D4 is updated in that worksheet



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$4" Then
If Target.Value = "No" Then
Rows("5:6").EntireRow.Hidden = True
ElseIf Target.Value = "Yes" Then
Rows("5:6").EntireRow.Hidden = False
End If
End If
End Sub





share|improve this answer
























  • Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

    – Jessica
    Apr 8 '16 at 15:28



















0














I received help from a friend and wanted to share the solution--below.



On Any update to the workbook that happens in column 4 (which is the Client Answer), if they answer No to a "Tiered Question"...the subsequent rows with a "Follow-Up Q" will be hidden.



You would have to update this macro if you moved the Business Criteria ("A") or Client Answer columns.



This should work:



Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer



If Target.Column = 4 Then
If Range("A" & Target.Row).Text = "Tiered Question" Then
i = 1
Do While Range("A" & Target.Row + i).Text = "Follow-Up Q"
Range("A" & Target.Row + i).EntireRow.Hidden = (Target.Value = "No")
i = i + 1
Loop
End If
End If


End Sub






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1062325%2fneed-help-to-hide-show-excel-rows-based-on-value-in-a-cell-but-allow-for-moving%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I'm not sure exactly what you mean by "manually updating every row" but if you put your code into a Worksheet_Change sub into your worksheet object (not a module) then it will run automatically every time cell D4 is updated in that worksheet



    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$4" Then
    If Target.Value = "No" Then
    Rows("5:6").EntireRow.Hidden = True
    ElseIf Target.Value = "Yes" Then
    Rows("5:6").EntireRow.Hidden = False
    End If
    End If
    End Sub





    share|improve this answer
























    • Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

      – Jessica
      Apr 8 '16 at 15:28
















    0














    I'm not sure exactly what you mean by "manually updating every row" but if you put your code into a Worksheet_Change sub into your worksheet object (not a module) then it will run automatically every time cell D4 is updated in that worksheet



    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$4" Then
    If Target.Value = "No" Then
    Rows("5:6").EntireRow.Hidden = True
    ElseIf Target.Value = "Yes" Then
    Rows("5:6").EntireRow.Hidden = False
    End If
    End If
    End Sub





    share|improve this answer
























    • Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

      – Jessica
      Apr 8 '16 at 15:28














    0












    0








    0







    I'm not sure exactly what you mean by "manually updating every row" but if you put your code into a Worksheet_Change sub into your worksheet object (not a module) then it will run automatically every time cell D4 is updated in that worksheet



    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$4" Then
    If Target.Value = "No" Then
    Rows("5:6").EntireRow.Hidden = True
    ElseIf Target.Value = "Yes" Then
    Rows("5:6").EntireRow.Hidden = False
    End If
    End If
    End Sub





    share|improve this answer













    I'm not sure exactly what you mean by "manually updating every row" but if you put your code into a Worksheet_Change sub into your worksheet object (not a module) then it will run automatically every time cell D4 is updated in that worksheet



    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$D$4" Then
    If Target.Value = "No" Then
    Rows("5:6").EntireRow.Hidden = True
    ElseIf Target.Value = "Yes" Then
    Rows("5:6").EntireRow.Hidden = False
    End If
    End If
    End Sub






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 7 '16 at 9:45









    CallumDACallumDA

    982718




    982718













    • Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

      – Jessica
      Apr 8 '16 at 15:28



















    • Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

      – Jessica
      Apr 8 '16 at 15:28

















    Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

    – Jessica
    Apr 8 '16 at 15:28





    Thanks CallumDA33. Sorry I didn't articulate better, but my issue is that I want D4 to trigger hide/unhide for Rows 5 and 6 as just one example. I also want D7 (my "Tiered Question") to trigger hide/unhide for rows 8 and 9 ("Follow-up Q"s), and D14 (Tiered) to trigger rows 15, 16, 17, (Follow up) and on and on through my 350 row sheet. Thanks so much for your help!

    – Jessica
    Apr 8 '16 at 15:28













    0














    I received help from a friend and wanted to share the solution--below.



    On Any update to the workbook that happens in column 4 (which is the Client Answer), if they answer No to a "Tiered Question"...the subsequent rows with a "Follow-Up Q" will be hidden.



    You would have to update this macro if you moved the Business Criteria ("A") or Client Answer columns.



    This should work:



    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer



    If Target.Column = 4 Then
    If Range("A" & Target.Row).Text = "Tiered Question" Then
    i = 1
    Do While Range("A" & Target.Row + i).Text = "Follow-Up Q"
    Range("A" & Target.Row + i).EntireRow.Hidden = (Target.Value = "No")
    i = i + 1
    Loop
    End If
    End If


    End Sub






    share|improve this answer




























      0














      I received help from a friend and wanted to share the solution--below.



      On Any update to the workbook that happens in column 4 (which is the Client Answer), if they answer No to a "Tiered Question"...the subsequent rows with a "Follow-Up Q" will be hidden.



      You would have to update this macro if you moved the Business Criteria ("A") or Client Answer columns.



      This should work:



      Private Sub Worksheet_Change(ByVal Target As Range)
      Dim i As Integer



      If Target.Column = 4 Then
      If Range("A" & Target.Row).Text = "Tiered Question" Then
      i = 1
      Do While Range("A" & Target.Row + i).Text = "Follow-Up Q"
      Range("A" & Target.Row + i).EntireRow.Hidden = (Target.Value = "No")
      i = i + 1
      Loop
      End If
      End If


      End Sub






      share|improve this answer


























        0












        0








        0







        I received help from a friend and wanted to share the solution--below.



        On Any update to the workbook that happens in column 4 (which is the Client Answer), if they answer No to a "Tiered Question"...the subsequent rows with a "Follow-Up Q" will be hidden.



        You would have to update this macro if you moved the Business Criteria ("A") or Client Answer columns.



        This should work:



        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim i As Integer



        If Target.Column = 4 Then
        If Range("A" & Target.Row).Text = "Tiered Question" Then
        i = 1
        Do While Range("A" & Target.Row + i).Text = "Follow-Up Q"
        Range("A" & Target.Row + i).EntireRow.Hidden = (Target.Value = "No")
        i = i + 1
        Loop
        End If
        End If


        End Sub






        share|improve this answer













        I received help from a friend and wanted to share the solution--below.



        On Any update to the workbook that happens in column 4 (which is the Client Answer), if they answer No to a "Tiered Question"...the subsequent rows with a "Follow-Up Q" will be hidden.



        You would have to update this macro if you moved the Business Criteria ("A") or Client Answer columns.



        This should work:



        Private Sub Worksheet_Change(ByVal Target As Range)
        Dim i As Integer



        If Target.Column = 4 Then
        If Range("A" & Target.Row).Text = "Tiered Question" Then
        i = 1
        Do While Range("A" & Target.Row + i).Text = "Follow-Up Q"
        Range("A" & Target.Row + i).EntireRow.Hidden = (Target.Value = "No")
        i = i + 1
        Loop
        End If
        End If


        End Sub







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 15 '16 at 16:31









        JessicaJessica

        111




        111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1062325%2fneed-help-to-hide-show-excel-rows-based-on-value-in-a-cell-but-allow-for-moving%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?