Private Sub Worksheet_Change(ByVal Target As Range)
arr = Sheets("Sheet2").Range("A1:B20").Value
For i = 1 To Sheets("Sheet2").Cells(Rows.Count, 1).End(3).Row '当sheet2a列数据超过20行时,会引发下标越界错误
For j = 1 To 2 '同样的事情重复两次,毫无意义
If Cells(i, 1) = arr(i, 1) Then
n = n + 1
Cells(i, 2) = arr(i, 2) '当if条件为真时,执行写入操作,将触发change事件,陷入无限循环
End If
Next
Next
End Sub