突出显示具有数值的单元格

use*_*267 5 excel vba excel-vba

我只想用数字突出显示单元格.此宏还突出显示带有文本的单元格.

Sub high()
    Dim ws As Worksheet
    Dim yourrange As Range

    Set ws = ActiveSheet

    For Each yourrange In ws.Cells.SpecialCells(xlCellTypeConstants)
        yourrange.Interior.Color = 65535
    Next yourrange
End Sub
Run Code Online (Sandbox Code Playgroud)

Dmi*_*liv 6

有两种选择:使用VBA而不使用WBA:

1)使用VBA

没有使用循环,感谢@Siddharth Rout :)

Sub high()
    Dim ws As Worksheet
    Dim rng As Range

    Set ws = ActiveSheet

    On Error Resume Next
    Set rng = ws.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
    On Error GoTo 0

    If Not rng Is Nothing Then rng.Interior.Color = 65535
End Sub
Run Code Online (Sandbox Code Playgroud)

使用循环:

Sub high()
    Dim ws As Worksheet
    Dim yourrange As Range
    Dim rng As Range

    Set ws = ActiveSheet

    On Error Resume Next
    Set rng = ws.Cells.SpecialCells(xlCellTypeConstants)
    On Error GoTo 0

    If Not rng Is Nothing Then
        For Each yourrange In rng
            If IsNumeric(yourrange) Then yourrange.Interior.Color = 65535
        Next yourrange
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

2)没有VBA,(感谢@pnuts):

转到功能区上的" 查找并选择 "菜单项,然后选择" GoTo Special .. ":

在此输入图像描述

选择" 常量 "并选择" 数字 "并按"确定".

在此输入图像描述

现在,excel突出显示所有数字单元格:

在此输入图像描述

下一步是用所需的颜色填充它们:

在此输入图像描述

完成:)