Results 1 to 8 of 8

Thread: How to make multiple, non adjacent cells hidden based on cell value code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,888
    Location
    1. Welcome to the Forum - suggest you take a look at the FAQs (in my sig)

    2. I added CODE tags to format the macro for you - you can use the [#] icon to insert CODE tags and paste the macro between

    3. No sure about the interplay between the two cells but something like this maybe on the code sheet for the worksheet



    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim v As Variant
        Dim r As Range
        Dim Rows39_47 As Boolean
        
        Set r = Target.Cells(1, 1)
        
        If Len(r.Value) = 0 Then Exit Sub  '   catch a Clear
        If Not Application.Intersect(Range("B2"), Target) Is Nothing Then
        
            Application.ScreenUpdating = False
                        
            Rows39_47 = Me.Rows("39:47").Hidden
            Me.Rows.Hidden = False
            Me.Rows("39:47").Hidden = Rows39_47
            
            Select Case UCase(r.Value)
                Case Is = "ACSA"
                    For Each v In Array(24, 25, 35, 36, 57, 58, 60)
                        Me.Rows(v).Hidden = True
                    Next
                Case Is = "CSA"
                    For Each v In Array(57, 58, 60)
                        Me.Rows(v).Hidden = True
                    Next
                Case Is = "ASA"
                    For Each v In Array(24, 25, 30, 31, 35, 36, 50, 57, 58, 59, 60)
                        Me.Rows(v).Hidden = True
                    Next
                Case Is = "ACA"
                    For Each v In Array(24, 25, 30, 31, 35, 36, 50, 59, 60)
                        Me.Rows(v).Hidden = True
                    Next
                Case Is = "SASA"
                    For Each v In Array(24, 25, 30, 31, 35, 36, 50, 57, 58, 59, 60)
                        Me.Rows(v).Hidden = True
                    Next
                Case Is = "PLEASE SELECT ROLE CODE"
                    '   empty for completeness
            End Select
            
            Application.ScreenUpdating = True
            
        
        ElseIf Not Application.Intersect(Range("D38"), Target) Is Nothing Then
        
            Application.ScreenUpdating = False
            
            Select Case UCase(r.Value)
                Case Is = "SELECT ANSWER"
                    Me.Rows("39:47").Hidden = False
                Case Is = "YES"
                    Me.Rows("39:47").Hidden = True
                Case Is = "NO"
                    Me.Rows("39:47").Hidden = False
                Case Is = "NA"
                    Me.Rows("39:47").Hidden = True
            End Select
            
            Application.ScreenUpdating = True
        
        End If
        
    End Sub
    Attached Files Attached Files
    Last edited by Paul_Hossler; 02-16-2018 at 08:55 AM. Reason: Tweaked code
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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