mardi 29 septembre 2020

VBA: nested With with If statement

Is nested With allowed in VBA? If it is, how to use it with IF statement?

I have the following nested With combined with If statement and compiler gave me an error message saying "End With without With".

With
If
    With
    End With
Else
    End With   <- End With without With
End If

I put the first With outside the IF statement because the IF statement can use it. Since the above code didn't work, I tried a different way. Another error message was obtained if I moved the first With inside the IF statement. This time, the error message says "Else without If". That leads me to wonder if nested With is allowed in VBA.

A google search turned up one hit, which is not exactly the same as my problem.

Aucun commentaire:

Enregistrer un commentaire