Sub test()
Dim xD, xD1, Ar(), Ar1(), T$, ky, L%, i&, j%, n%, n1%
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
xR = Range("b3")
For j = 0 To UBound(Split(xR, ","))
T = Split(xR, ",")(j): xD(T) = 1
Next
xR1 = Range("c3")
For j = 0 To UBound(Split(xR1, ","))
T = Split(xR1, ",")(j): xD1(T) = 1
Next
For Each ky In xD
If xD1(ky) <> 1 Then: ReDim Preserve Ar(n): Ar(n) = ky: n = n + 1
Next
For Each ky In xD1
If xD(ky) <> 1 Then: ReDim Preserve Ar1(n1): Ar1(n1) = ky: n1 = n1 + 1
Next
If n1 > 0 Then
For j = 0 To UBound(Ar1)
T = Ar1(j): L = Len(T): pos = InStr(Range("c3"), T)
Range("c3").Characters(pos, L).Font.ColorIndex = 3
Next
End If
If n > 0 Then
For j = 0 To UBound(Ar)
T = Ar(j): L = Len(T): pos = InStr(Range("b3"), T)
Range("b3").Characters(pos, L).Font.ColorIndex = 3
Next
End If
End Sub作者: ikboy 時間: 2021-8-29 21:56
Cells(3, i + 2).Characters(j, ln).Font.Color = vbRed
Next
End If
Next
End Sub
複製代碼
作者: ML089 時間: 2021-8-29 22:15
Sub test()
Set xB = [B3]
Set xC = [C3]
While xB <> ""
If xB.Value <> xC.Value Then
Call NotFindChar(xB, xC)
Call NotFindChar(xC, xB)
End If
Set xB = xB(2, 1)
Set xC = xC(2, 1)
Wend
Debug.Print "time", Time
End Sub
Sub NotFindChar(xC, xS)
ArrC = Split(xC.Value, ",")
For i = 0 To UBound(ArrC)
If InStr("," & xS & ",", "," & ArrC(i) & ",") = 0 Then
nS = InStr("," & xC & ",", "," & ArrC(i) & ",")
nL = Len(ArrC(i))
With xC.Characters(Start:=nS, Length:=nL).Font
.FontStyle = "粗體"
.Color = vbRed '紅色 -16777024
End With
End If
Next
End Sub作者: samwang 時間: 2021-8-30 07:27
我原先程式修改位置 *1 *2 *3
Sub test()
' 清除字顏色及粗體
With Range("B3:C" & [C65536].End(xlUp).Row).Font
.ColorIndex = xlAutomatic
.Bold = False
End With
Set xB = [b3]
Set xC = [c3]
While xB <> ""
If xB.Value <> xC.Value Then
Call NotFindChar(xB, xC)
Call NotFindChar(xC, xB)
End If
Set xB = xB(2, 1)
Set xC = xC(2, 1)
Wend
Debug.Print "time", Time
End Sub
Sub NotFindChar(xC, xS)
ArrC = Split(xC.Value, ",")
nStart = 1 '*1
For i = 0 To UBound(ArrC)
If InStr("," & xS & ",", "," & ArrC(i) & ",") = 0 Then
nS = InStr(nStart, "," & xC & ",", "," & ArrC(i) & ",") '*2
nL = Len(ArrC(i))
' Range("b3").Characters(pos, L).Font.ColorIndex = 3
' Cells(3, i + 2).Characters(j, ln).Font.Color = vbRed
With xC.Characters(Start:=nS, Length:=nL).Font
.FontStyle = "粗體"
.Color = vbRed '紅色 -16777024
End With
End If
nStart = nStart + nL + 1 '*3
Next
End Sub作者: samwang 時間: 2021-8-30 11:42
Sub test()
Dim xD, xD1, Ar(), Ar1(), T$, ky, L%, i&, j%, n%, n1%, xP%, xP1
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
xR = Range("b3")
For j = 0 To UBound(Split(xR, ","))
T = Split(xR, ",")(j): xD(T) = xD(T) + 1
Next
xR1 = Range("c3")
For j = 0 To UBound(Split(xR1, ","))
T = Split(xR1, ",")(j): xD1(T) = xD1(T) + 1
Next
For Each ky In xD
If Not xD1.exists(ky) Then: ReDim Preserve Ar(n): Ar(n) = ky: n = n + 1
Next
For Each ky In xD1
If Not xD.exists(ky) Then: ReDim Preserve Ar1(n1): Ar1(n1) = ky: n1 = n1 + 1
Next
If n1 > 0 Then
For j = 0 To UBound(Ar1)
T = Ar1(j): L = Len(T)
For j1 = 1 To xD1(T)
If j1 = 1 Then
pos = InStr(Range("c3"), T)
Else
pos = InStr(xP, Range("c3"), T)
End If
Range("c3").Characters(pos, L).Font.ColorIndex = 3
xP = pos + 2
Next
Next
End If
If n > 0 Then
For j = 0 To UBound(Ar)
T = Ar(j): L = Len(T)
For j1 = 1 To xD(T)
If j1 = 1 Then
pos = InStr(Range("b3"), T)
Else
pos = InStr(xP1, Range("b3"), T)
End If
Range("b3").Characters(pos, L).Font.ColorIndex = 3
xP1 = pos + 2
Next
Next
End If
End Sub作者: samwang 時間: 2021-8-30 14:28
Sub test2()
Dim R, xR, xR1, xD, xD1, Ar(), Ar1(), ky
Dim T$, L%, i&, j%, n%, n1%, xP%, xP1%, pos%
Set xD = CreateObject("Scripting.Dictionary")
Set xD1 = CreateObject("Scripting.Dictionary")
On Error Resume Next
Set xR = Application.InputBox("請選擇Range:", Type:=8)
Set xR1 = Application.InputBox("請選擇Range:", Type:=8)
For Each R In xR: For j = 0 To UBound(Split(R, ","))
T = Split(R, ",")(j): xD(T) = xD(T) + 1
Next j: Next R
For Each R In xR1: For j = 0 To UBound(Split(R, ","))
T = Split(R, ",")(j): xD1(T) = xD1(T) + 1
Next j: Next R
For Each ky In xD
If Not xD1.exists(ky) Then: ReDim Preserve Ar(n): Ar(n) = ky: n = n + 1
Next
For Each ky In xD1
If Not xD.exists(ky) Then: ReDim Preserve Ar1(n1): Ar1(n1) = ky: n1 = n1 + 1
Next
If n1 > 0 Then
For j = 0 To UBound(Ar1)
For Each R In xR1
T = Ar1(j): L = Len(T): xP = 1
For j1 = 1 To xD1(T)
pos = InStr(xP, R, T, 0)
If pos > 0 Then
R.Characters(pos, L).Font.ColorIndex = 3
xP = pos + 2
End If
Next j1
Next R
Next j
End If
If n > 0 Then
For j = 0 To UBound(Ar)
For Each R In xR
T = Ar(j): L = Len(T): xP1 = 1
For j1 = 1 To xD(T)
pos = InStr(xP1, R, T, 0)
If pos > 0 Then
R.Characters(pos, L).Font.ColorIndex = 3
xP1 = pos + 2
End If
Next j1
Next R
Next j
End If
End Sub作者: free72921 時間: 2021-8-30 23:02