I have a variable fila
with a full line with Excel's values
The problem is when in Excel I have #N/A
, VBA takes that value like Error 2042
.
I cannot assign that value to valor
and produce an error. Until this point everything is ok, now I am trying to define a On Error Goto
to go to the next iteration in the For
loop, but I do not know why VBA doesn't handle the error.
Do While Not IsEmpty(ActiveCell)
txt = ActiveCell.Value2
cell = ActiveCell.Offset(0, 1).Value2
fila = Range("C20:F20")
For j = 1 To UBound(fila, 2)
On Error GoTo Siguiente
If Not IsEmpty(fila(1, j)) Then
valor = fila(1, j)
cmd = Cells(1, j + 2).Value2
devolver = function1(cmd, txt, cell, valor)
arrayDevolver(p) = devolver
p = p + 1
End If
Siguiente:
Next
Loop
This is not a VBA error - so error handling won't catch it. To detect this issue use IsError
before writing to your array
The simple code below handles the Error 2042 problem with this test
Sub Test()
Dim varIn As Variant
[a1].FormulaR1C1 = "=NA()"
If IsError([a1].Value2) Then
varIn = "skip record"
Else
varIn = [a1].Value2
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With