Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Specific range formating

I have a sheet where I only want the code to effect certain parts of rows
(ie. D6:G6, D10:G10, D14:G14, etc). I want to apply conditional formatting.
The CF function only allows 3 conditions, and I need 4 so I thought I would
try it with VBA.
I want to look at each of the cells in the specified ranges and if it's
greater than 95, a certain color, between 90 and 95 another color, less than
90 a different color and if the cell has "N/A", to be black.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Specific range formating

Try using this Worksheet Change event code in your sheet's code window....

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count = 1 Then
If Application.WorksheetFunction.IsNA(.Value) Then
.Interior.Color = vbBlack
ElseIf Application.WorksheetFunction.IsErr(.Value) Then
.Interior.Color = RGB(127, 127, 127)
ElseIf .Value Like "*[!0-9]*" Then
.Interior.ColorIndex = xlNone
ElseIf .Value 95 Then
.Interior.Color = vbGreen
ElseIf .Value 89 Then
.Interior.Color = vbYellow
Else
.Interior.Color = vbRed
End If
End If
End With
End Sub

You didn't say what to do if an error other than #N/A were to occur, so I
made those cells a dark gray, were such a condition happen.

Rick


"aimee209" wrote in message
...
I have a sheet where I only want the code to effect certain parts of rows
(ie. D6:G6, D10:G10, D14:G14, etc). I want to apply conditional
formatting.
The CF function only allows 3 conditions, and I need 4 so I thought I
would
try it with VBA.
I want to look at each of the cells in the specified ranges and if it's
greater than 95, a certain color, between 90 and 95 another color, less
than
90 a different color and if the cell has "N/A", to be black.

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Specific range formating

I think my test for numeric values is too strict (it requires numeric
entries to be integer values; that is, not floating point). Here is a more
general test allowing all numeric values to be treated as numeric...

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count = 1 Then
If Application.WorksheetFunction.IsNA(.Value) Then
.Interior.Color = vbBlack
ElseIf Application.WorksheetFunction.IsErr(.Value) Then
.Interior.Color = RGB(127, 127, 127)
ElseIf Not IsNumeric(.Value) Then
.Interior.ColorIndex = xlNone
ElseIf .Value 95 Then
.Interior.Color = vbGreen
ElseIf .Value 89 Then
.Interior.Color = vbYellow
Else
.Interior.Color = vbRed
End If
End If
End With
End Sub

Rick


"Rick Rothstein (MVP - VB)" wrote in
message ...
Try using this Worksheet Change event code in your sheet's code window....

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Count = 1 Then
If Application.WorksheetFunction.IsNA(.Value) Then
.Interior.Color = vbBlack
ElseIf Application.WorksheetFunction.IsErr(.Value) Then
.Interior.Color = RGB(127, 127, 127)
ElseIf .Value Like "*[!0-9]*" Then
.Interior.ColorIndex = xlNone
ElseIf .Value 95 Then
.Interior.Color = vbGreen
ElseIf .Value 89 Then
.Interior.Color = vbYellow
Else
.Interior.Color = vbRed
End If
End If
End With
End Sub

You didn't say what to do if an error other than #N/A were to occur, so I
made those cells a dark gray, were such a condition happen.

Rick


"aimee209" wrote in message
...
I have a sheet where I only want the code to effect certain parts of rows
(ie. D6:G6, D10:G10, D14:G14, etc). I want to apply conditional
formatting.
The CF function only allows 3 conditions, and I need 4 so I thought I
would
try it with VBA.
I want to look at each of the cells in the specified ranges and if it's
greater than 95, a certain color, between 90 and 95 another color, less
than
90 a different color and if the cell has "N/A", to be black.

Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formating Specific Text andreabeas Excel Discussion (Misc queries) 3 March 25th 09 08:20 PM
Count If Specific word in specific range [email protected] Excel Discussion (Misc queries) 2 May 16th 06 10:14 AM
CONDITIONAL FORMATING FINDING TEXT CONTAINING SPECIFIC NUMBERS Twiggy Excel Worksheet Functions 4 April 12th 06 09:13 AM
conditional formating a specific amount of cells in a row. jeff New Users to Excel 3 April 4th 06 06:07 PM
search a series of rows for a specific formating Harris Excel Worksheet Functions 2 July 30th 05 11:46 PM


All times are GMT +1. The time now is 11:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"