求公式:EXCEL表格里输入三位数,三个数字中有两个到三个相同则自动成红字,怎么设置?

2024-12-22 17:41:37
推荐回答(4个)
回答1:

我给的方法是用宏,打开你的表格,我假设你的数字放在A列,且是三位数字,按ALT + F11,双击左面的“SHEET1(你的表名)”,粘贴如下代码后,按F5,
Sub Choose()
Dim i As Integer
i = i + 1
For i = 2 To 500
Dim lft1 As String
Dim mid1 As String
Dim rit1 As String
lft1 = Left(Sheets(1).Cells(i, 1).Value, 1)
mid1 = Right(Left(Sheets(1).Cells(i, 1).Value, 2), 1)
rit1 = Right(Sheets(1).Cells(i, 1).Value, 1)
If Sheets(1).Cells(i, 1).Value <> "" And lft1 = mid1 Then
Sheets(1).Cells(i, 1).Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
End If
If Sheets(1).Cells(i, 1).Value <> "" And lft1 = rit1 Then
Sheets(1).Cells(i, 1).Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
End If
If Sheets(1).Cells(i, 1).Value <> "" And mid1 = rit1 Then
Sheets(1).Cells(i, 1).Select
With Selection.Font
.Color = -16776961
.TintAndShade = 0
End With
End If
Next i
End Sub

回答2:

不会有一位数吧?可以试试这个公式。
=ISNUMBER(MODE(--MID(TEXT(A1,"000;@"),{1,2,3},1)))

回答3:

=IF(LEN(T(A1))>0,OR(IF(LEN(A1)=3,OR(NOT(ISERROR(FIND("1",A1,2))),MID(A1,2,1)=MID(A1,3,1)),0),IF(LEN(A1)=2,MID(A1,1,1)=MID(A1,2,1),0)),FALSE())

回答4:

......