在 excel 中突出显示包含乱序发票编号的单元格

highlighting cells which contain out of sequence invoice numbers in excel

您好,我正在尝试突出显示 excel 中乱序的发票编号。

我的 B 列显示发票编号。通常发票号码包含 2 个字母和 6 个数字,例如 AA123456。我想突出显示不符合此条件的单元格。

请帮忙。

非常感谢。

以下代码检查 3 个条件:如果值长度为 8,如果最后 6 个字符是数字,如果前 2 个字符是文本。然后将单元格颜色更改为红色。只需将搜索范围更改为所需的范围即可。希望这适合你。

Sub check()
    Dim cell, searchRng As Range
    Set searchRng = Range("b1:b10")
    For Each cell In searchRng.Cells
        If Not Len(cell) = 8 Then
            cell.Interior.ColorIndex = 3
            GoTo iteration:
        End If
        If Not IsNumeric(Right(cell.Value, 6)) Then
            cell.Interior.ColorIndex = 3
            GoTo iteration:
        End If
        If Not Application.WorksheetFunction.IsText(Left(cell.Value, 2)) Then
            cell.Interior.ColorIndex = 3
            GoTo iteration:
        End If
iteration:
    Next cell
End Sub