|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
以下是我的代码,目的是先检查行和列项目符合条件与否;然后在符合条件的前提下对比数据区域的单元内数据是否相等,相等就添加颜色,不相等就插入批注,标注两者之差。怎么往符合条件的单元格里添加颜色和插入备注,试了很多方法都不行,整了好几天了,都没有办法搞定这个事情,求助呀!
Sub comparision()
Dim table1, table2 As Workbook
Dim sht1, sht2 As Worksheet
Dim i&, j&, d, e, Arr, Brr, x$, y, z, Crr()
Application.ScreenUpdating = False
Set table1 = ThisWorkbook
Set table2 = Workbooks.Open(table1.Path & "\检查源表.xls")
Set sht1 = table1.Worksheets("检查表")
Set sht2 = table2.Worksheets("检查源表")
Set e = CreateObject("Scripting.Dictionary")
Arr = sht1.[a1].CurrentRegion
Brr = sht2.[a1].CurrentRegion
For i = 2 To UBound(Brr)
x = Brr(i, 9)
For j = 14 To UBound(Brr, 2)
y = Brr(1, j)
If e.exists(x) = False Then Set e(x) = CreateObject("Scripting.Dictionary")
e(x)(y) = Brr(i, j)
Next
Next
table2.Close False
For i = 2 To UBound(Arr)
x = Arr(i, 9)
If e.exists(x) Then
For j = 14 To (UBound(Arr, 2))
y = Arr(1, j)
If e(x).exists(y) Then
z = Arr(i, j)
If e(x)(y) = z Then
'这里向数据区域单元格添加颜色,表示相同项
Else
''这里向数据区域单元格插入备注,表示不同项目
End If
End If
Next j
End If
Next i
Application.ScreenUpdating = True
End Sub
|
|