Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Conditional Formatting

Hi,

I am trying to conditionally format my worksheet based on the
following conditions:

If cell value = target and cell value = last year's result then
color cell green
If cell value < target and cell value = last years' result then color
cell yellow
If cell value < target and cell value < last year's result then color
cell red

I know you have to do this with vb but I am only a beginner and am not
sure where to start.

Also the target value is stored in a cell but it changes based on the
data element that is looked at. If you could get me started that
would be great.

Thanks,
Jaime
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional Formatting



Sub whatColor()
Dim c As Range
target = Range("C2").Value
lyrslts = Range("D2").Value
lr = Cells(Rows.Count, 1).End(xlUp).Row
Set fRng = Worksheets(1).Range("A2:A" & lr)
For Each c In fRng
If c.Value = target And c.Value = lyrslts Then
c.Interior.ColorIndex = 4
ElseIf c.Value < target And c.Value = lyrslts Then
c.Interior.ColorIndex = 6
ElseIf c.Value < target And c.Value < lyrslts Then
c.Interior.ColorIndex = 3
End If
Next
End Sub

" wrote:

Hi,

I am trying to conditionally format my worksheet based on the
following conditions:

If cell value = target and cell value = last year's result then
color cell green
If cell value < target and cell value = last years' result then color
cell yellow
If cell value < target and cell value < last year's result then color
cell red

I know you have to do this with vb but I am only a beginner and am not
sure where to start.

Also the target value is stored in a cell but it changes based on the
data element that is looked at. If you could get me started that
would be great.

Thanks,
Jaime

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Conditional Formatting

I hit the trigger too quick there.

Assuming there is a range of values you want to
check located in cells A2 through A(n). Assuming
the Target is a fixed value and the last year's
results is a fixed value. Assuming your range to
check will be of varying length and all data is
on Sheet 1. Change any that are not true.

Sub whatColor()
Dim c As Range
target = Range("C2").Value
lyrslts = Range("D2").Value
lr = Cells(Rows.Count, 1).End(xlUP).Row
Set fRng = Worksheets(1).Range("A2:A" & lr)
For Each c In fRng
If c.Value = target And c.Value = lyrslts Then
c.Interior.ColorIndex = 4
ElseIf c.Value < target And c.Value = lyrslts Then
c.Interior.ColorIndex = 6
ElseIf c.Value < target And c.Value < lyrslts Then
c.Interior.ColorIndex = 3
End If
Next
End Sub

" wrote:

Hi,

I am trying to conditionally format my worksheet based on the
following conditions:

If cell value = target and cell value = last year's result then
color cell green
If cell value < target and cell value = last years' result then color
cell yellow
If cell value < target and cell value < last year's result then color
cell red

I know you have to do this with vb but I am only a beginner and am not
sure where to start.

Also the target value is stored in a cell but it changes based on the
data element that is looked at. If you could get me started that
would be great.

Thanks,
Jaime

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Conditional Formatting

On Dec 6, 2:51 pm, JLGWhiz wrote:
I hit the trigger too quick there.

Assuming there is a range of values you want to
check located in cells A2 through A(n). Assuming
the Target is a fixed value and the last year's
results is a fixed value. Assuming your range to
check will be of varying length and all data is
on Sheet 1. Change any that are not true.

Sub whatColor()
Dim c As Range
target = Range("C2").Value
lyrslts = Range("D2").Value
lr = Cells(Rows.Count, 1).End(xlUP).Row
Set fRng = Worksheets(1).Range("A2:A" & lr)
For Each c In fRng
If c.Value = target And c.Value = lyrslts Then
c.Interior.ColorIndex = 4
ElseIf c.Value < target And c.Value = lyrslts Then
c.Interior.ColorIndex = 6
ElseIf c.Value < target And c.Value < lyrslts Then
c.Interior.ColorIndex = 3
End If
Next
End Sub



" wrote:
Hi,


I am trying to conditionally format my worksheet based on the
following conditions:


If cell value = target and cell value = last year's result then
color cell green
If cell value < target and cell value = last years' result then color
cell yellow
If cell value < target and cell value < last year's result then color
cell red


I know you have to do this with vb but I am only a beginner and am not
sure where to start.


Also the target value is stored in a cell but it changes based on the
data element that is looked at. If you could get me started that
would be great.


Thanks,
Jaime- Hide quoted text -


- Show quoted text -


Thanks! This is a great start for me. Actually my target value and
last year value are not fixed. Basically in each row there is a
target, a last years result, and the data from let's say C3:F3. So I
need the conditional formating to work for cells C3:F3: where C1=
target and C2= last year's result. And I need that to iterate for 4
rows.
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
Formatting Conditional Formatting Icon Sets The Rook[_2_] Excel Discussion (Misc queries) 3 March 7th 09 08:48 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 3 January 20th 07 02:02 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


All times are GMT +1. The time now is 05:20 PM.

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"