Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
No Interior Color Macro | Excel Discussion (Misc queries) | |||
lock cells based on interior color | Excel Discussion (Misc queries) | |||
Print without Interior Color | Excel Discussion (Misc queries) | |||
Passing Back Color to Interior Color | Excel Programming |