Forum Discussion

hrh_dash's avatar
hrh_dash
Iron Contributor
Oct 02, 2022
Solved

IF function does not populate when condition met

Would like to know what is wrong with the IF function for the code below as it does not populate the expected text "waive admin fee" when condition is met..   Private Sub Worksheet_Change(ByVal Ta...
  • HansVogelaar's avatar
    HansVogelaar
    Oct 04, 2022

    hrh_dash 

    Wouldn't it be easier to enter the following formula in L2 and fill down?

    =IF(AND(K2>0,K2<=10),"waive admin fee","")

    If you prefer the event procedure:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rng As Range
        If Not Intersect(Range("K2:K" & Rows.Count), Target) Is Nothing Then
            Application.ScreenUpdating = False
            Application.EnableEvents = False
            For Each rng In Intersect(Range("K2:K" & Rows.Count), Target)
                If rng.Value > 0 And rng.Value <= 10 Then
                    rng.Offset(0, 1).Value = "waive admin fee"
                Else
                    rng.Offset(0, 1).ClearContents
                End If
            Next rng
            Application.EnableEvents = True
            Application.ScreenUpdating = True
        End If
    End Sub

     

Resources