Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel vba比较类似列表_Excel_List - Fatal编程技术网

Excel vba比较类似列表

Excel vba比较类似列表,excel,list,Excel,List,我有两张清单非常相似的表格。范例 Column A Column B 1 1 2 3 3 3.5 4 4 4.5 5 5 我应该将缺少的元素添加到B中,然后从B中删除多余的元素。我不是在寻找复制粘贴,这些数字实际上是链接,在复制和删除之前我将运行宏。所以 Call add(2) Call add(4.5) Call remove(3.5) 有没有比走路更快的方法 for (all elements in

我有两张清单非常相似的表格。范例

Column A   Column B
1          1
2          3
3          3.5
4          4
4.5        5
5
我应该将缺少的元素添加到B中,然后从B中删除多余的元素。我不是在寻找复制粘贴,这些数字实际上是链接,在复制和删除之前我将运行宏。所以

Call add(2)
Call add(4.5)
Call remove(3.5)
有没有比走路更快的方法

for (all elements in A)
   for (all elements in B)
      if (they match) then mark as ok
delete all non marked in B
add all non marked in A
感觉很慢,我不知道如何“标记”

Option Explicit

Sub test()

    Dim varSheetA As Variant
    Dim varSheetB As Variant
    Dim strRangeToCheck As String
    Dim iRow As Long
    Dim iCol As Long

    strRangeToCheck = "A1:IV65536"
    ' If you know the data will only be in a smaller range, reduce the size of the ranges above.
    Debug.Print Now
    varSheetA = Worksheets("Sheet1").Range(strRangeToCheck)
    varSheetB = Worksheets("Sheet2").Range(strRangeToCheck) ' or whatever your other sheet is.
    Debug.Print Now

    For iRow = LBound(varSheetA, 1) To UBound(varSheetA, 1)
        For iCol = LBound(varSheetA, 2) To UBound(varSheetA, 2)
            If varSheetA(iRow, iCol) = varSheetB(iRow, iCol) Then
                ' Cells are identical.
                ' Do nothing.
            Else
                ' Cells are different.
                ' Code goes here for whatever it is you want to do.
            End If
        Next iCol
    Next iRow

End Sub

尝试使用此设置,并且在else语句中,您需要创建一个打印字符串,以便它可以说明此值是否与此匹配

当您说因为数字是链接而无法复制/粘贴时,您的意思是a列包含链接、公式等;而B列只包含值?如果是这样,你考虑粘贴值吗?