我只想用数字突出显示单元格。该宏还突出显示带有文本的单元格。
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):
转到功能区上的“查找并选择”菜单项,然后选择“ GoTo Special .. ”:
选择“常数”,然后仅选择“数字”,然后按“确定”。
现在,excel突出显示了所有数字单元格:
下一步是用所需的颜色填充它们:
完毕:)
关于excel - 用数值突出显示单元格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21438892/