Results 1 to 10 of 380

Thread: Appendix Thread. ( Codes for other Threads, etc.) Event Coding Drpdown Data validation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    In support of answer to this post
    https://excel.tips.net/T001940_Hidin...ell_Value.html

    2020-06-19 11:13:59
    Erica
    This is my script:

    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Column = 3 And Target.Row = 5 Then
    If Target.Value = "Yes" Then
    Application.Sheets("FAR").Select
    Application.Rows("14").Select
    Application.Selection.EntireRow.Hidden = False
    Application.Sheets("Additions").Select
    Application.Rows("6").Select
    Application.Selection.EntireRow.Hidden = False
    ElseIf Target.Value = "No" Then
    Application.Sheets("FAR").Select
    Application.Rows("14").Select
    Application.Selection.EntireRow.Hidden = True
    Application.Sheets("Additions").Select
    Application.Rows("6").Select
    Application.Selection.EntireRow.Hidden = True
    End If
    End If
    End Sub
    How do I make this continue for the next 19 rows?

    The idea is to:
    hide row 14 in Tab FAR and Row 7 in Tab Additions if the value in row 6 Tab Additions is "NO" and leave unhidden if yes
    hide row 15 in Tab FAR and Row 8 in Tab Additions if the value in row 7 Tab Additions is "NO" and leave unhidden if yes
    hide row 16 in Tab FAR and Row 9 in Tab Additions if the value in row 8 Tab Additions is "NO" and leave unhidden if yes

    and so fort 20 times

    Please can you help me with the reloop of this script
    ........




    Hello Erica
    I expect you may have got your macro using the macro recorder? Using the macro recorder is a very good idea as it can easily get you your required syntax and initial coding.
    Often we can simplify the macro given by the recorder, in particular bearing in mind that VBA does not need to select or activate things as we do. We have to click on a cell, or row, for example in order to do anything with it. That results in code lines involving Activateing and Selecting. VCBA does not need those actions. Bearing this in mind, and making a few other minor modifications I can simplify your given macro to
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Column = 3 And Target.Row = 5 Then
            If Target.Value = "Yes" Then
             Let Worksheets("FAR").Rows("14").Hidden = False
             Let Worksheets("Additions").Rows("6").Hidden = False
            ElseIf Target.Value = "No" Then
             Let Worksheets("FAR").Rows("14").Hidden = True
             Let Worksheets("Additions").Rows("6").Hidden = True
            End If
        End If
    End Sub
    Further to simplify, we can add an initial code line that will limit the most of the macro to running only when a change occurs in the range of interest, which , if I am correct is range C5 to C24 in worksheets Additions
    After this, we no longer need to have the check for the column 3
    So now we have this
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Application.Intersect(Target, Me.Range("C5:C24")) Is Nothing Then Exit Sub
        If Target.Row = 5 Then        '       Target.Column = 3 And Target.Row = 5 Then
            If Target.Value = "Yes" Then
             Let Worksheets("FAR").Rows("14").Hidden = False
             Let Worksheets("Additions").Rows("6").Hidden = False
            ElseIf Target.Value = "No" Then
             Let Worksheets("FAR").Rows("14").Hidden = True
             Let Worksheets("Additions").Rows("6").Hidden = True
            End If
        End If
    End Sub
    
    We can now start to make your coding "dynamic" so that it could be used, for example, in a Loop. But I will start considering your ….hide row 14 in Tab FAR and Row 7 in Tab Additions if the value in row 6 Tab Additions is "NO" and leave unhidden if yes ….
    I will leave the coding for row 5 and 6 since it does not seem to fit your pattern, since you are hiding or un hidding row 14 also for row 5 and 6


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxUbeYSvsBH2Gianox4AaABAg.9VYH-07VTyW9gJV5fDAZNe
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgyhQ73u0C3V4bEPhYB4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgzIElpI5OFExnUyrk14AaABAg.9fsvd9zwZii9gMUka-NbIZ
    https://www.youtube.com/watch?v=jdPeMPT98QU
    https://www.youtube.com/watch?v=QdwDnUz96W0&lc=Ugx3syV3Bw6bxddVyBx4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-12-2023 at 05:11 PM.

Similar Threads

  1. Replies: 192
    Last Post: 08-30-2025, 01:34 AM
  2. Replies: 293
    Last Post: 09-24-2020, 01:53 AM
  3. Appendix Thread. Diet Protokol Coding Adaptions
    By DocAElstein in forum Test Area
    Replies: 6
    Last Post: 09-05-2019, 10:45 AM
  4. Restrict data within the Cell (Data Validation)
    By dritan0478 in forum Excel Help
    Replies: 1
    Last Post: 07-27-2017, 09:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •