gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:45:59 41 4
gpt4 key购买 nike

我只想突出显示带有数字的单元格。该宏还突出显示带有文本的单元格。

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

最佳答案

有两种选择供您选择:使用 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

使用循环:

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) 没有 VBA,(感谢 @pnuts):

转到功能区上的“查找和选择”菜单项,然后选择“转到特殊..”:

enter image description here

选择“常量”并选择“数字”,然后按“确定”。

enter image description here

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

enter image description here

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

enter image description here

完成:)

关于excel - 突出显示具有数值的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21438892/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com