T
T
ti_zh_vrach2021-04-10 20:32:19
Visual Basic
ti_zh_vrach, 2021-04-10 20:32:19

How to check if a value is in a list in VBA?

Good afternoon.
I'm trying to implement validation:

For row_values = 2 To row_values_end
    Call do_any_here
    If something Then
        For row_db = 2 To row_db_end
            On Error GoTo error_handler
            If data_base.Cells(row_db, 6).Value <> special_values Then Err.Raise 1013, "another_sub", "неверные данные"
            Call do_any_there
            On Error GoTo 0
        Next row_db 
    End If
Next row_values

special_values ​​must contain two String values. It is necessary that the error does not occur if data_base.Cells(row_db, 6) is equal to at least one of the two values ​​in special_values. There are many options for data_base.Cells(row_db, 6). We need an implementation that does not require a large number of steps (ideally one). The fact is that this check is needed for a macro that can check this way and not several hundred thousand cells. Macro performance in general is a separate issue.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ti_zh_vrach, 2021-04-11
@ti_zh_vrach

Found a workaround.

If data_base.Cells(row_db, 6).Value <> "энач1" Then If data_base.Cells(row_db, 6).Value <> "энач2" Then Err.Raise 1013, "another_sub", "неверные данные"

There is another option with Collections, which has not worked out to the end. But it seems that it will also be reduced to a double If. Or to search in a cycle.
The question in the title is open.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question