|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test1() '数组
Dim ar, br, i&, j&
With [A2].CurrentRegion
ar = .Value
.Interior.ColorIndex = xlNone
For i = 1 To UBound(ar)
If ar(i, 2) <> "" Then
For j = 1 To UBound(ar)
If ar(j, 1) = ar(i, 2) Then
.Cells(j, 1).Interior.Color = vbYellow
.Cells(i, 3) = ar(j, 1)
Exit For
End If
Next j
End If
Next i
End With
Beep
End Sub
Sub test2() '字典
Dim ar, i&, dic As Object
Set dic = CreateObject("Scripting.Dictionary")
With [A2].CurrentRegion
ar = .Value
.Interior.ColorIndex = xlNone
For i = 1 To UBound(ar): dic(ar(i, 1)) = i: Next
For i = 1 To UBound(ar)
If dic.exists(ar(i, 2)) Then
.Cells(i, 3) = ar(i, 2)
.Cells(dic(ar(i, 2)), 1).Interior.Color = vbYellow
End If
Next i
End With
Beep
End Sub |
评分
-
2
查看全部评分
-
|