Forum Discussion

SamM750's avatar
SamM750
Copper Contributor
Dec 12, 2024

I need a little help

I've played around with the code and I still can not get it to execute the command.

 

Here is the code in question.

 

If [C2] = "Initial Legal Filing" And [C34] = "Two Defendants-Served at Different Addresses" Then

     Sheets("Sheriff's Svc-Addtl Address").Visible = True
Else
     Sheets("Sheriff's Svc-Addtl Address").Visible = False
     
End If

 

Its probably something simple and I just don't see it. No matter what is selected in C34 the sheet is always visible. :/

2 Replies

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    add code to the Workbook_SheetChange event:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    Const YOUR_SHEET As String = "SHEET1"
    
        If UCase(Sh.Name) = YOUR_SHEET Then
                With ActiveSheet
                    If .Range("$C$2") & "" = "Initial Legal Filing" And .Range("$C$34") & "" = "Two Defendants-Served at Different Addresses" Then
                        Sheets("Sheriff's Svc-Addtl Address").Visible = -1
                    Else
                        Sheets("Sheriff's Svc-Addtl Address").Visible = 0
                    End If
                End With
        End If
                    
    End Sub

     

  • m_tarler's avatar
    m_tarler
    Bronze Contributor

    I would make sure the values are correct.  I would use debug and step through and the immediate pane (ctrl-g) to test each component.  for example 

    print [C34]="Two Defendants-Served at Different Addresses"

    and see if it returns TRUE

    and also in the immediate pane you can

    Sheets('Sheriff's Svc-Addtl Address").Visible = False

    and see if that works

     

Resources