Conditional Formatting

towera

New Member
Joined
Oct 5, 2012
Messages
4
Hi,

I need to write a macro that will fill in a row depending on one cell's value
ie if Saturday or Sunday Highlight row blue
I also need to highlight cells if they return certain values
S - red
H, AM, PM - green

At the moment I can do either or but can not work out how to get both options
Thanks in advance


<TBODY>
</TBODY>
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You should write a macro that iterates through every cell in the range that you need to validate.

And then iterate with a for loop through each cell, if the value is "saturday" or other specific words, it should change the colorindex of the interior of the cell in that loop.
 
Upvote 0
<CODE>Something like this, but define your range how you want:

Dim mycell As Range

For Each mycell In ActiveSheet.UsedRange.Cells

If mycell.Value = "Saturday" Then

With mycell.Interior
.ColorIndex = 1
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End If
Next mycell


</CODE></PRE>
 
Upvote 0
Hi,

doesn't that just work for if the cell value equals Saturday. This is similar to how I have done the second part of my query but it did not work to highlight the entire row if cell B3 is Saturday
 
Upvote 0
Hi,

I need to combine:-

Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPlage = Range("C3:M368")
For Each Cell In MyPlage

If Cell.Value = "S" Then
Cell.Interior.ColorIndex = 38
End If
If Cell.Value = "H" Then
Cell.Interior.ColorIndex = 35
End If
If Cell.Value = "PM" Then
Cell.Interior.ColorIndex = 35

End If
If Cell.Value = "AM" Then
Cell.Interior.ColorIndex = 35
End If

If Cell.Value <> "H" And Cell.Value <> "S" And Cell.Value <> "AM" And Cell.Value <> "PM" Then
Cell.Interior.ColorIndex = xlNone
End If

Next
End Sub

and
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$B3=""Saturday"""
Selection.FormatConditions(1).Interior.ColorIndex = 41
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$B3=""Sunday"""
Selection.FormatConditions(2).Interior.ColorIndex = 41
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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