Hello,
I have a line in my code that may return an error in some specific case. When it happens I'd like to force a value, then continue my code. I read a bit about the "On error GoTo", but seems I don't use it correctly
Here is what I did
The line
is the line which can return an error. If there is an error I want to do
Then exit my Do and continue the rest of my code.
What am I missing?
I have a line in my code that may return an error in some specific case. When it happens I'd like to force a value, then continue my code. I read a bit about the "On error GoTo", but seems I don't use it correctly
Here is what I did
Code:
Do Until surplus = 0
adr = "AF" & lmin & ":AF" & lmax & ""
If lmax - lmin = 0 Then
min = Application.WorksheetFunction.Subtotal(5, Range(Cells(lmin, "AF"), Cells(lmax, "AF")))
lig = Evaluate("=MATCH(SUBTOTAL(5,(AF" & lmin & ":AF" & lmax & ")),AF" & lmin & ":AF" & lmax & ",0)")
Cells(lig + lmin - 1, 30) = Cells(lig + lmin - 1, 30) + 1
surplus = surplus - 1
Else
On Error GoTo ErrHandler:
min2 = Evaluate("aggregate(15,6," & adr & "/(" & adr & ">min(" & adr & ")),1)")
lig = Evaluate("match(aggregate(15,6," & adr & "/(" & adr & ">min(" & adr & ")),1)," & adr & ",0)")
Cells(lig + lmin - 1, 30) = Cells(lig + lmin - 1, 30) + 1
surplus = surplus - 1
Exit Do
ErrHandler:
Cells(lig + lmin - 1, 30) = Cells(lig + lmin - 1, 30) + surplus
surplus = 0
Resume Next
End If
The line
Code:
min2 = Evaluate("aggregate(15,6," & adr & "/(" & adr & ">min(" & adr & ")),1)")"
is the line which can return an error. If there is an error I want to do
Code:
Cells(lig + lmin - 1, 30) = Cells(lig + lmin - 1, 30) + surplus
surplus = 0
Then exit my Do and continue the rest of my code.
What am I missing?
Last edited: