|
发表于 2023-2-26 17:33
来自手机
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub JudgeColor()
Dim rng As Range, i As Long, j As Long, k As Byte, str As String, strColor
Dim blnWzRed As Boolean, blnWzBlack As Boolean, blnBdRed As Boolean
Dim blnBdBlack As Boolean, blnNoRed As Boolean, blnNoBlack As Boolean
Dim rg As Range, Bd As String
'自定义需要过滤的标点符号,Chr(34)表示英文状态下的双引号
Bd = ",。?;:“’”‘!!'?,.、" & Chr(34)
Set rng = Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row)
Set rng = Intersect(ActiveSheet.UsedRange, rng)
For i = 2 To rng.Rows.Count
blnWzRed = False
blnWzBlack = False
blnBdRed = False
blnBdBlack = False
blnNoRed = False
blnNoBlack = False
Set rg = rng.Cells(i, 1)
For j = 1 To Len(rg.Value)
With rg.Characters(Start:=j, Length:=1)
str = .Text
strColor = .Font.ColorIndex
End With
If InStr(1, Bd, str) > 0 Then
If strColor = 3 Then blnBdRed = True Else blnBdBlack = True
ElseIf IsNumeric(str) Then
If strColor = 3 Then blnNoRed = True Else blnNoBlack = True
Else
If strColor = 3 Then blnWzRed = True Else blnWzBlack = True
End If
If blnWzRed And blnWzBlack Then Exit For
Next j
If blnWzRed And blnWzBlack Then
rng.Cells(i, 2).Value = "mixed"
ElseIf blnWzRed Then
If Not blnBdBlack And Not blnNoBlack Then
rng.Cells(i, 2).Value = "red"
ElseIf blnBdBlack And blnNoBlack Then
rng.Cells(i, 2).Value = "red (忽略标点符号和数字颜色)"
ElseIf blnBdBlack Then
rng.Cells(i, 2).Value = "red (忽略标点符号颜色)"
Else
rng.Cells(i, 2).Value = "red (忽略数字颜色)"
End If
ElseIf blnWzBlack Then
If Not blnBdRed And Not blnNoRed Then
rng.Cells(i, 2).Value = "black"
ElseIf blnBdRed And blnNoRed Then
rng.Cells(i, 2).Value = "black (忽略标点符号和数字颜色)"
ElseIf blnBdRed Then
rng.Cells(i, 2).Value = "black (忽略标点符号颜色)"
Else
rng.Cells(i, 2).Value = "black (忽略数字颜色)"
End If
End If
Next i
End Sub |
评分
-
1
查看全部评分
-
|