Highlight Cells with numerical value

excel, vba

Solution

There are two options for you: with VBA and without WBA:

1) Using VBA

without using loop, thanks to @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):

Go to "Find & Select" menu Item on the Ribbon and select "GoTo Special..":

choose "Constants" and select only "Numbers" and press "OK".

Now, excel highlighted all number cells:

Next step is to fill them with desired color:

Done:)

Problem

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 ```

Original source