LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Interior color based on dates

Hi Michael,

Reading your last post in conjunction with your earlier posts, it is not
easy to decipher your requirements.

Taking the plunge I have assumed that what you want that:

- The first row having a date in column J should be colored

- Each subsequent row should be colored using the same color

- At each month change the color should change

On these assumptions, try:

Sub ColorByMonth3()
Dim Rng As Range, rng2 As Range
Dim rCell As Range
Dim WB As Workbook
Dim WS As Worksheet
Dim iDate As Long
Dim fCell As Range, lCell As Range
Dim finalCell As Range


Set WB = ThisWorkbook
Set WS = WB.Sheets("Sheet1")

WS.Cells.Interior.ColorIndex = xlNone

Set Rng = Intersect(WS.UsedRange, WS.Columns("J"))
If Rng Is Nothing Then Exit Sub

Set Rng = Rng.Resize(Rng.Cells.Count + 1)
Set finalCell = Rng.Cells(Rng.Cells.Count)

For Each rCell In Rng
If IsDate(rCell) Or rCell.Address = finalCell.Address Then
If Month(rCell) < iDate Then
iDate = Month(rCell)
On Error Resume Next
If Not Intersect(rCell.Offset(-1), _
ActiveSheet.UsedRange) Is Nothing Then
Set lCell = rCell.Offset(-1)
End If
On Error GoTo 0
If Not lCell Is Nothing Then

On Error GoTo XIT
Set rng2 = Range(lCell, fCell)
On Error GoTo 0

Set rng2 = rng2.Offset(, -9).Resize(, 13)

With rng2.Interior
Select Case Month(fCell.Value)
Case 1: .ColorIndex = 35
Case 2: .ColorIndex = 3
Case 3: .ColorIndex = 4
Case 4: .ColorIndex = 5
Case 5: .ColorIndex = 6
Case 6: .ColorIndex = 15
Case 7: .ColorIndex = 16
Case 8: .ColorIndex = 17
Case 9: .ColorIndex = 18
Case 10: .ColorIndex = 19
Case 11: .ColorIndex = 8
Case 12: .ColorIndex = 7
End Select
End With
End If
Set fCell = rCell
End If
End If
Next

Exit Sub

If my assumptions are incorrect, post back.

---
Regards,
Norman



"Michael Wise"
wrote in message
news:Michael.Wise.1rg06p_1120140451.4342@excelforu m-nospam.com...

Yep option 2 I appologize I failed to mention that columns A thru I do
not have dates only column J. And I failed to mention that column K,L,M
also need to change so the whole row of Columns A-M need to change based
on the date of column J. Sorry for not clarifing


--
Michael Wise
------------------------------------------------------------------------
Michael Wise's Profile:
http://www.excelforum.com/member.php...fo&userid=6998
View this thread: http://www.excelforum.com/showthread...hreadid=383309



 
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
No Interior Color Macro simplymidori[_2_] Excel Discussion (Misc queries) 1 April 11th 08 05:01 AM
lock cells based on interior color MIke Excel Discussion (Misc queries) 4 December 27th 07 08:59 PM
Print without Interior Color bhofsetz Excel Discussion (Misc queries) 2 July 19th 05 04:28 PM
Passing Back Color to Interior Color ExcelMonkey[_190_] Excel Programming 1 March 22nd 05 04:27 PM


All times are GMT +1. The time now is 11:44 PM.

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

About Us

"It's about Microsoft Excel"