|
- Option Explicit
- Sub demo()
- Dim area As Range
-
- Set area = Worksheets("样表").Range("b8:j30000")
-
- Dim nameDic As Object, temp, i#, count#, tempRange As Range
-
- Set nameDic = CreateObject("scripting.dictionary")
-
- For Each temp In area.Value
-
- If temp <> "" Then
-
- Set tempRange = area.Find(What:=temp, After:=area.Cells(1), LookIn:=-4176, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=True)
-
- count = 1
-
- For i = tempRange.Column - area.Cells(1).Column + 2 To 9
-
- Set tempRange = area.Columns(i).Find(What:=temp, After:=area.Columns(i).Cells(1), LookIn:=-4176, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=True)
-
- If Not tempRange Is Nothing Then
-
- count = count + 1
-
- Else
- count = 0
- End If
-
-
- If count > 2 Then
-
- nameDic(temp) = ""
-
- Exit For
- End If
- Next
-
- End If
- Next
-
- Dim firstRangeAddress$, nextRange As Range
-
- For Each temp In nameDic.keys
- Set tempRange = area.Find(What:=temp, After:=area.Cells(1), LookIn:=-4176, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, MatchByte:=False, SearchFormat:=True)
- Set nextRange = area.FindNext(After:=tempRange)
-
- tempRange.Interior.Color = 65535
-
- While nextRange.Address <> tempRange.Address
-
- nextRange.Interior.Color = 65535
-
- Set nextRange = area.FindNext(After:=nextRange)
-
- Wend
-
- Next
-
- Set nameDic = Nothing
-
- Set tempRange = Nothing
-
- Set nextRange = Nothing
-
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|