|
代码如下。。。。。
Sub test_字符多一()
Dim wb As Workbook, sht As Worksheet
Set wb = ThisWorkbook
Set sht = wb.Sheets("sheet1")
' s = Split("水 工国")
s = sht.[g5:g25]
Set d = CreateObject("scripting.dictionary")
For i = 1 To UBound(s)
ss = s(i, 1)
If ss <> Empty Then
If Not d.exists(ss) Then
n = n + 1
d(ss) = n
End If
End If
Next
With sht
r = .Cells(Rows.Count, 3).End(3).Row
arr = .Range("c1:c" & r)
.Range("c1:c" & r).Font.ColorIndex = 1
Key = d.keys
For i = 1 To UBound(arr)
sss = arr(i, 1)
If sss <> Empty Then
For k = 0 To UBound(Key)
x = 1
For j = 1 To Len(sss)
y = InStr(x, sss, Key(k))
If y Then
.Cells(i, 3).Characters(y, Len(Key(k))).Font.ColorIndex = 3
j = y + Len(Key(k))
x = y + Len(Key(k)) + 1
Else
Exit For
End If
Next
Next
End If
Next
End With
Beep
Set d = Nothing
End Su |
|