T
T
ti_zh_vrach2021-03-29 22:09:41
Visual Basic
ti_zh_vrach, 2021-03-29 22:09:41

Why is 1000 = "no" True?

Good afternoon!
There is a piece of working code:

On Error Resume Next
For row_port = 2 To row_port_end
    For row_abc = 2 To row_abc_end
        If Int(portion.Cells(row_port, 6).Value) = Int(abc.Cells(row_abc, 5).Value) Then Call any_do
    Next row_abc
Next row_port
On Error GoTo 0

Exception handling is needed to keep the macro running 24/7. Both sides of the equation receive numbers as a string. Left - incoming data. On the right is the base where the string "no" has got. Should have been zero. Without exception handling, we will fall into error 13 (type mismatch). And when there is processing, then, when the word hits the right side, the result of the comparison is True for some reason. Why is this happening? Is there any way to get around or fix this behavior with VBA?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akelsey, 2021-03-29
@ti_zh_vrach

Make a normal handler:

For row_port = 2 To row_port_end
    For row_abc = 2 To row_abc_end
      On Error GoTo ErrHandler
        val1 = Int(portion.Cells(row_port, 6).Value)
        val2 = Int(abc.Cells(row_abc, 5).Value) 
        If  val1  =  val2 Then Call any_do
    Next row_abc
Next row_port
Exit Sub
:ErrHandler
  val1=0
  val2=0
Resume Next

PS
Well, of course, correct the logic there, since you need val2=0 or only val1=0...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question