highlighting cells above a certain number

Lyn Radnell

New Member
Joined
Sep 4, 2011
Messages
7
Hi,

Can anyone help me?

Out of a group of cells, I would like to highlight any cells over the the number 15 and any highlight in a different colour lower than the number 2

Appreciate any help.

Lyn
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

Can anyone help me?

Out of a group of cells, I would like to highlight any cells over the the number 15 and any highlight in a different colour lower than the number 2

Appreciate any help.

Lyn
You'll need to use Conditional Formatting. Here's some help:
http://www.contextures.com/xlCondFormat01.html

If you need more specific direction, then post back with
- what version of Excel you are using
- what the range of cells you are dealing with is
- are there (or could there be) any blank cells in the range?
 
Upvote 0
The following is an example code for you, just paste it into the worksheet event.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="="""""""""""""
    Selection.FormatConditions(1).Font.ColorIndex = xlAutomatic
    Selection.FormatConditions(1).Interior.Pattern = xlNone
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
        Formula1:="2"
    Selection.FormatConditions(2).Interior.ColorIndex = 6
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
        , Formula1:="15"
    Selection.FormatConditions(3).Interior.ColorIndex = 3
End Sub
 
Upvote 0
The following is an example code for you, just paste it into the worksheet event.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, _
        Formula1:="="""""""""""""
    Selection.FormatConditions(1).Font.ColorIndex = xlAutomatic
    Selection.FormatConditions(1).Interior.Pattern = xlNone
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _
        Formula1:="2"
    Selection.FormatConditions(2).Interior.ColorIndex = 6
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
        , Formula1:="15"
    Selection.FormatConditions(3).Interior.ColorIndex = 3
End Sub
That code can have some strange results. :eeek:
 
Upvote 0
How can I apply this macro to just Columns D and H?
Welcome to the MrExcel board!

1. Why do you need to do this with code? Why not just manually apply the Conditional Formatting to columns D and H?

If you do need to use code, I suggest that you probably don't want the code above. It was supposed to colour entries >=15 red and entries <=2 yellow. However, as I mentioned previously it can produce some unexpected results.

To get the best suggestion, we need a bit more information. For example,

2. Do columns D and H contain any formulas or will the values always be entered manually?

3. What version of Excel are you using?

4. Is it >=15 and <=2 that you want coloured? If not, more details please.

5. What do you want to happen to the cell colour if the cell is empty (since this could be considered as less than 2)?
 
Last edited:
Upvote 0
Welcome to the MrExcel board!
Thank you Peter! Thank you for replying to my response as I have been searching the forums for help.

1. Why do you need to do this with code? Why not just manually apply the Conditional Formatting to columns D and H?
I tried to use Conditional Formatting but when cut and pasting on to a new sheet (same workbook) the Conditional Formatting did not hold. I noticed some highlighted cells were moved up a cell or down a cell.
If you do need to use code, I suggest that you probably don't want the code above. It was supposed to colour entries >=15 red and entries <=2 yellow. However, as I mentioned previously it can produce some unexpected results.

To get the best suggestion, we need a bit more information. For example,

2. Do columns D and H contain any formulas or will the values always be entered manually?
Actually, I have Columns D, E, and H that need to be filtered. These columns will randomly have date entered here. Here are my specifics:
Cells should be highlighted if:
Column D: blank, or greater than 9999999, or contain letters/words
Column E: blank, or contain letters or words
Column H: blank, less than 200000000, greater than 999999999, or contain letters or words.
3. What version of Excel are you using?
I am using MS Excel 2003.
4. Is it >=15 and <=2 that you want coloured? If not, more details please.

5. What do you want to happen to the cell colour if the cell is empty (since this could be considered as less than 2)?[/QUOTE]
A normal yellow highlight should be fine for any of the findings above.

Thanks for your help in advance.
dadomi
 
Last edited:
Upvote 0
Try this in a fresh worksheet.

1. Select D1:Dx (or whatever range in column D you want the Conditional Formatting to apply to. Even the whole column if you really want, though I wouldn't recommend that since CF can slow your sheet performance if you have too much of it).

2. Apply the CF shown below for D1. (If your range does not start in row 1 then just ensure that where I have D1, you put whatever the active cell in your column D selection is)

3. Repeat the above steps for columns E and H.

If the results below are not what you were trying to describe, then please elaborate.

You should be able to copy any of these cells/ranges to another locatuion and the CF should 'hold'.

Excel Workbook
DEFGH
1252525
2ddd
3999999999999999999
4cat dogcat dogcat dog
5100000001000000010000000
6161616
716.285616.285616.2856
8
9200001000200001000200001000
10
dadomi CF
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D11. / Formula is =OR(D1="",D1>9999999)Abc
E11. / Formula is =NOT(ISNUMBER(E1))Abc
H11. / Formula is =OR(H1<200000000,H1>999999999)Abc
 
Upvote 0
Thank you Peter! It works great. But do you know how I can copy or cut any rows consisting of any highlighted cells on to a new sheet within the same workbook?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top