如何检查其他数组vba中是否存在数组值

时间:2014-04-25 02:04:15

标签: vba access-vba

我有两个数组,第一个是Litems(i),第二个是tcols(k)。如何使用访问VBA检查tcol(k)数组中的数组Litems(i)值。

1 个答案:

答案 0 :(得分:2)

尝试以下方法查找匹配值:

Dim lSize1  As Long
Dim lSize2  As Long
Dim lX1     As Long
Dim lX2     As Long
lSize1 = UBound(Litems)
lSize2 = UBound(tcols)
For lX1 = 1 To lSize1
   For lX2 = 1 To lSize2
       If Litems(lX1) = tcols(lX2) Then
          Debug.Print "Match: Litems item " & lX1 & " = tcols item " & lX2 & vbTab & "Value = " & Litems(lX1)
       End If
   Next lX2
Next lX1

尝试以下方法查找不匹配的值:

Dim lSize1  As Long
Dim lSize2  As Long
Dim lX1     As Long
Dim lX2     As Long
dim blnFound as Boolean

lSize1 = UBound(Litems)
lSize2 = UBound(tcols)

For lX1 = 1 To lSize1
   blnFound = False  
   For lX2 = 1 To lSize2
       If Litems(lX1) = tcols(lX2) Then
          blnFound = True
       End If
   Next lX2
   If blnFound = False Then
      Debug.Print "No Match for: Litems item " & lX1 
   End If
Next lX1