首页 > 解决方案 > 如何将 Line2 中的每个单元格与 Line1 进行比较

问题描述

我正在开发一个脚本,它将遍历 line2 中的每个单元格,并在 Line1 中找到相同的单元格,并计算有多少是相同的。现在我被困住了。

Sub compare()
final_col = Cells(7, 250).End(xlToLeft).Column
Dim i As Integer, j As Integer
Dim Line1 As Range
Dim Line2 As Range
Match = 0

Line1 = Range(Cells(4, 7), Cells(7, final_col))
Line2 = Range(Cells(12, 7), Cells(7, final_col))

For Each i In Line2
   For Each j In Line1
      If i = j Then
         Match = +1
      End If
   Next j
Next i

End Sub

为每个循环填充数据的最佳方法是什么。

标签: excelvba

解决方案


推荐阅读