Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight Cells with numerical value

Tags:

excel

vba

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
like image 932
user3147267 Avatar asked Jan 29 '14 17:01

user3147267


People also ask

How do I highlight cells based on numbers?

On the Home tab, in the Style group, click the arrow next to Conditional Formatting, and then click Highlight Cells Rules. Select the command you want, such as Between, Equal To Text that Contains, or A Date Occurring. Enter the values you want to use, and then select a format.

How do you highlight cells with numbers in Excel?

Select the range of cells, the table, or the whole sheet that you want to apply conditional formatting to. On the Home tab, click Conditional Formatting. Point to Highlight Cells Rules, and then click Text that Contains. Type the text that you want to highlight, and then click OK.

How do you highlight cells with matching values?

To select the duplicate values, from the dropdown menu of Conditional Formatting, select Highlight Values and then select Duplicate Values. Choose the formatting you'd want to apply to the duplicate values, and you are done. You may also highlight duplicate values within each column separately.

How do I highlight only cells with data?

Select one or more rows and columns Or click on any cell in the column and then press Ctrl + Space. Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.


1 Answers

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..":

enter image description here

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

enter image description here

Now, excel highlighted all number cells:

enter image description here

Next step is to fill them with desired color:

enter image description here

Done:)

like image 127
Dmitry Pavliv Avatar answered Oct 05 '22 09:10

Dmitry Pavliv