|
代码如下,供测试:代码放在1号工作表内。
- Sub fyExcelVBA()
- Dim arr, brr, i%, dic As Object
- Dim path1$, path2$
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- Set dic = CreateObject("scripting.dictionary")
- Set dic1 = CreateObject("scripting.dictionary")
- path1 = ThisWorkbook.path & ""
- path2 = path1 & "出库明细-2.xlsx"
- arr = Range("a1").CurrentRegion
- For i = 2 To UBound(arr)
- dic(arr(i, 1)) = ""
- Next i
- With Workbooks.Open(path2)
- brr = .Sheets(1).Range("a1").CurrentRegion
- For i = 2 To UBound(brr)
- dic1(brr(i, 1)) = ""
- If dic.exists(brr(i, 1)) Then
- .Sheets(1).Cells(i, 1).Interior.ColorIndex = 8
- ' .Sheets(1).Cells(i, 1) = ""
- End If
- Next i
- .Close 1
- End With
- For i = 2 To UBound(arr)
- If dic1.exists(arr(i, 1)) Then
- Cells(i, 1).Interior.ColorIndex = 8
- End If
- Next i
- Set dic = Nothing
- Set dic1 = Nothing
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|