|
Sub 设置背景色()
Dim ar As Variant, br As Variant
Dim i As Long, r As Long, rs As Long
Dim d As Object
Set d = CreateObject("scripting.dictionary")
Set sh = Sheets("sheet1")
With sh
r = .Cells(Rows.Count, 14).End(xlUp).Row
ar = .Range("n1:n" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 1)) <> "" Then
d(Trim(ar(i, 1))) = i
End If
Next i
End With
With Sheets("sheet2")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
br = .Range("a1:a" & rs)
.Range("a1:a" & rs).Interior.ColorIndex = 2
For i = 2 To UBound(br)
If Trim(br(i, 1)) <> "" Then
xh = d(Trim(br(i, 1)))
If xh <> "" Then
ys = sh.Cells(xh, 14).Interior.ColorIndex
.Cells(i, 1).Interior.ColorIndex = ys
End If
End If
Next i
End With
MsgBox "ok!"
End Sub |
|