PDA

View Full Version : Formting and Adapting



marreco
01-15-2012, 02:57 PM
The master decided mikerikson
Thank you!

See...
Sub Teste()

Dim oneCell As Range
Dim lngColor As Long

For Each oneCell In Range("B1:D1")
oneCell.Resize(6, 1).Interior.ColorIndex = xlNone
If IsDate(oneCell.Value) Then
If oneCell.Value < Date Then
lngColor = vbRed
ElseIf oneCell.Value = Date Then
lngColor = vbYellow
Else
lngColor = vbGreen
End If
oneCell.Resize(6, 1).Interior.Color = lngColor
End If
Next oneCell
End Sub



Hi...

How do I adapt the code below?


They should follow the following conditions criterion.




If the cell "B1" is less than today's date then the range "B1: B6" will be the color Red.


If the cell "B1" is equal to today's date then the range "B1: B6" will be yellow.


If the cell "B1" is greater than today's date then the range "B1: B6" will be the color green.

but I also need it done in the "C1" and range "C1:C6" and "D1" range "D1:D6"

Sub Format()
Dim x As Integer
For x = 2 To 4
If Cells(1, x) > Date Then
Cells(1, x).Resize(6, 1).Interior.ColorIndex = x + 1
End If
Next
End Sub

Crosspost
http://www.ozgrid.com/forum/showthread.php?t=161461
Thank's

mikerickson
01-15-2012, 08:35 PM
There isn't any need to start a new thread, you could have continued with the other thread.

The code I posted does what you require.
It looks like both the codes should do what you want other than the second bit of code, the color is dependent on which column it is applied to.