2023-02-19

Rows will not unhide

I'm new to VBA and this forum. I'm encountering the following problem; I've written a code that first hides a range and is then supposed to unhide the relevant rows based on the value in the target range. The hide is working, but my code doesn't unhide anything:

This is the sub for hiding and unhiding:

Sub Hide(row As Double, dExtras As Double)
    'Hide rij op basis van argument
    Rows(row & ":" & row + dExtras).EntireRow.Hidden = True
    
End Sub

Sub Unhide(row As Double, dExtras As Double)
    'Unhide rij op basis van argument
    Rows(row & ":" & row + dExtras).EntireRow.Hidden = False

End Sub

And this is the code that calls these subs:

Sub AlertsShowHide()

    Dim wsTemplate As Worksheet
    Dim i As Long, lAantalAlerts As Long

    Set wsTemplate = ThisWorkbook.Worksheets("Template")

    With wsTemplate

        lAantalAlerts = .Range("aantalAlerts")
    
        'Hide all
        .Range(.Range("aantalAlerts").Offset(2, 0), .Range("antVoorgaandeAlerts").Offset(-3, 0)).EntireRow.Hidden = True
    
        'Unhide relevant alerts
        For i = 1 To lAantalAlerts

        'Unhide in/out/voeding rows
            Call AlertsRow(.Range("antEachAlertType" & CStr(i)))
        
        'Only works up to 6 alerts
            If i = 6 Then Exit For

        Next i
    
    'Unhide extra room for process more than 6 alerts
        If lAantalAlerts > 6 Then
            Call Unhide(.Range("antAlertToelicht7").row, 0)
            MsgBox "Bij meer dan 6 alerts handmatig de beschrijving toevoegen van deze extra alerts onderaan bij vakje 'Toelichting MEER DAN 6 alerts'", vbOKOnly, "Veel alerts"
        End If
    
    End With

End Sub
Sub AlertsRow(target As Range)
    'Unhide de relevant rijen Inkomnde, Uitgaande en/of voeding afhankelijk van gekozen alert(s)

    ' Hide all
    Call Hide(target.Offset(1, 0).row, 58)
    
    ' Unhide header
    Call Unhide(target.Offset(-3, 0).row, 3)
    
    ' Unhide toelichting
    Call Unhide(target.Offset(57, 0).row, 2)
    
   'Determine which alerts to unhide
    If target.Value Like "*WWFT*" Then
        Call Unhide(target.Offset(1, 0).row, 3)
    End If
    If target.Value Like "*Credit on Card*" Then
        Call Unhide(target.Offset(5, 0).row, 2)
    End If
    If target.Value Like "*Funding*" Then
        Call Unhide(target.Offset(8, 0).row, 1)
    End If
    If target.Value Like "*Crypto & Trading*" Then
        Call Unhide(target.Offset(10, 0).row, 3)
    End If
    If target.Value Like "*Gambling*" Then
        Call Unhide(target.Offset(14, 0).row, 3)
    End If
    If target.Value Like "*Money transfer*" Then
        Call Unhide(target.Offset(18, 0).row, 3)
    End If
    If target.Value Like "*P2P*" Then
        Call Unhide(target.Offset(22, 0).row, 3)
    End If
    If target.Value Like "*Passing through*" Then
        Call Unhide(target.Offset(26, 0).row, 3)
    End If
    If target.Value Like "*Activation of a dormant account*" Then
        Call Unhide(target.Offset(30, 0).row, 2)
    End If
    If target.Value Like "*Cash*" Then
        Call Unhide(target.Offset(33, 0).row, 2)
    End If
    If target.Value Like "*Donations*" Then
        Call Unhide(target.Offset(36, 0).row, 2)
    End If
    If target.Value Like "*High Risk Terrorism Activities*" Then
        Call Unhide(target.Offset(39, 0).row, 2)
    End If
    If target.Value Like "*High Risk Terrorism Countries*" Then
        Call Unhide(target.Offset(42, 0).row, 2)
    End If
    If target.Value Like "*Sanction High Risk Offshore*" Then
        Call Unhide(target.Offset(45, 0).row, 2)
    End If
    If target.Value Like "*Smurfen*" Then
        Call Unhide(target.Offset(48, 0).row, 2)
    End If
    If target.Value Like "*Transfer to bank account*" Then
        Call Unhide(target.Offset(51, 0).row, 1)
    End If
    If target.Value Like "*Trx on card*" Then
        Call Unhide(target.Offset(54, 0).row, 2)
    End If

End Sub

I've tried to add a watch to the target value, to see if this is correct. Which it is. So it seems like the Unhide() sub is not working. However when I try hard coding with this sub, it does work. What am I missing?



No comments:

Post a Comment