|
- Sub FindSameNumber()
- Dim dNumber As Object
- Set dNumber = CreateObject("scripting.dictionary")
- Dim aFind
- Dim i As Long, lngRow As Long, s As Long
- Dim aColor(1 To 3) As Long
-
- aFind = Range([a1], Cells(Rows.Count, "b").End(xlUp))
- For i = 1 To UBound(aFind)
- dNumber(aFind(i, 1)) = i
- Next
-
- Range("a1").CurrentRegion.Interior.Pattern = xlNone
- Range([c1], Cells(Rows.Count, "c").End(xlUp)).ClearContents
- For i = 1 To UBound(aFind)
- If dNumber.exists(aFind(i, 2)) Then
- lngRow = dNumber(aFind(i, 2))
- For s = 1 To 3
- aColor(s) = Application.WorksheetFunction.RandBetween(-70, 50) + 200
- Next
-
- Cells(lngRow, 1).Interior.Color = RGB(aColor(1), aColor(2), aColor(3))
- Cells(i, 3) = aFind(i, 2)
- End If
- Next
-
- aFind = Range("A1").CurrentRegion
- For i = 1 To UBound(aFind)
- If aFind(i, 2) = aFind(i, 3) Then
- lngRow = dNumber(aFind(i, 2))
- Cells(i, 2).Interior.Color = Cells(lngRow, 1).Interior.Color
- Cells(i, 3).Interior.Color = Cells(lngRow, 1).Interior.Color
- End If
- Next
- End Sub
复制代码
|
|