Hi all,

I'm trying to get more familiar with Error Handling in VBA. I am using below code and need to set the value of my variables x and y to 0 every time an error occurs. What is the best way of doing that?

Basically, if it cannot find the TextBox in my UserForm or if there's a divison error, it should set the variable y or x to 0, if there's no error, it should calculate/lookup the actual value and then resume to the last bit of my module where x and y are compared and the TextBox coloured accordingly.

Sub HandleError()

    Dim i As Long
            
    For i = 1 To UBound(Evaluate(ActiveWorkbook.Names("L4_Values").RefersTo))
            
        Dim x As Long
        Dim y As Long
                
        On Error GoTo SetValue
                
        x = MultiPage1.Pages("Page_" & Region).Controls("TextBox_" & Region & "_Disc_" & DSSN & "_" & i).Value
        y = Evaluate("ROUND(SUMIFS(Metric_" & Region & "_SE_MDS,Attribute_PLLevel4,INDEX(L4_Values," & i & "))/" & SSMU & ",1)")
                
        Resume Continue
                
SetValue:
    
        x = 0
        y = 0
    
Continue:
                
        With MultiPage1.Pages("Page_" & Region).Controls("TextBox_" & Region & "_Disc_" & DSSN & "_" & i)
            If x = y Then
                .BackColor = RGB(223, 243, 249)
            Else
                .BackColor = RGB(71, 142, 185)
            End If
        End With
             
    Next i

End Sub