简体   繁体   English

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

[英]Highlight Cells with numerical value

I just want to highlight cell with number. 我只想用数字突出显示单元格。 This macro highlights cell with text also. 此宏还突出显示带有文本的单元格。

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

There are two options for you: with VBA and without WBA: 有两种选择:使用VBA而不使用WBA:

1) Using VBA 1)使用VBA

without using loop, thanks to @Siddharth Rout:) 没有使用循环,感谢@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

Using loop: 使用循环:

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

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

Go to " Find & Select " menu Item on the Ribbon and select " GoTo Special.. ": 转到功能区上的“ 查找并选择 ”菜单项,然后选择“ GoTo Special .. ”:

在此输入图像描述

choose " Constants " and select only " Numbers " and press "OK". 选择“ 常量 ”并选择“ 数字 ”并按“确定”。

在此输入图像描述

Now, excel highlighted all number cells: 现在,excel突出显示所有数字单元格:

在此输入图像描述

Next step is to fill them with desired color: 下一步是用所需的颜色填充它们:

在此输入图像描述

Done:) 完成:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM