我试图比较两个列表中的值。我希望我的代码比较第一个列表中的值,并检查第二个列表中的所有条目。如果有匹配,则代码将在第一个列表中的值旁边打印true,如果不匹配,则将打印false。
我遇到的问题是,我的代码只比较同一行中的值。
代码运行,我在两个较小的列表上尝试过,以确保数据类型是相同的,并且列表中没有任何额外的空格或逗号会导致"False“输出。我也尝试过更改for和if语句的顺序,但这也不起作用。
Sub findvalues()
    For i = 2 To 16
        For j = 2 To 16
            If Cells(i, 3).Value = Cells(i, 1).Value Then
                Cells(i, 4).Value = "TRUE"
            ElseIf Cells(i, 3).Value = Cells(j + 1, 1).Value Then
                Cells(i, 4).Value = "TRUE"
            Else
                Cells(i, 4).Value = "FALSE"
            End If
        Next j
    Next i
End Sub发布于 2019-04-25 13:55:05
VBA代码来协调两个列表。
 Sub Reconciliation()
Dim endRow As Long
Dim ICount As Long
Dim Match1() As Variant
Dim Match2() As Variant
Dim ws As Worksheet
Set ws = Worksheets("Recon")
ICount = 0
endRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
endRow1 = ws.Cells(ws.Rows.Count, 11).End(xlUp).Row
Match1 = Sheet1.Range("b2:b" & endRow)
Match2 = Sheet1.Range("K2:K" & endRow1)
For i = LBound(Match1) To UBound(Match1)
For j = LBound(Match2) To UBound(Match2)
    If Match1(i, 1) = Match2(j, 1) Then
    ICount = ICount + 1
        Sheet1.Range("C" & i + 1).Value = ICount
        Sheet1.Range("L" & j + 1).Value = ICount
    Else
   End If
   Next j
Next i
End Subhttps://stackoverflow.com/questions/55849395
复制相似问题