LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 202
Default colorindex = xlnone on condition of month of year

Please see my code below. What is happening here is when the month changes
to Aug for example certain background colors which were colored in Jul will
now be colored in Aug. Everything works except Now that we are in the month
of Aug, Jul background colors are still colored and I now do not want those
cells to have color anymore. The only coloring should be in current month,
mmm. Can you help fix my code. Very new to this. Thank you.

' ALSO, HOW DO I MAKE THIS CODE ACTIVATE WHEN I OPEN THE WORKBOOK?
'HOW DO I CHANGE THIS CODE SO IT WORKS FOR SPECIFIC SHEETS (I.E. SHEET1,
SHEET2, ETC.) BUT NOT ALL SHEETS
'WHEN I OPEN THE WORKBOOK?
Sub CFormat()

Dim rng As Range, cell As Range
Dim ncol As Integer, lrow As Long
Dim pcnt As Double, divisor As Double

'Sheet1 is sheet name
ThisWorkbook.Worksheets("Sheet1").Activate

' Find column for current Month (add 5 to start in colum F onwards)
' Define "CurMonth" and "HdrMonths" in spreadsheet
ncol = Application.WorksheetFunction.match(Range("a3"), Range("F3:Q3"), 0) + 5

' Find last row of data in current month column
lrow = Cells(Rows.Count, 1).End(xlUp).Row

Range("F9:Q500").Select
'Clears the colours
'Selection.Interior.ColorIndex = xlNone 'THIS STATEMENT DELETES ALL CELL
BACKGROUND COLOR WHICH
'IS NOT WHAT I NEED...I NEED SOMETHING LIKE THE FOLLOWING..

Select Case
Case Is = Interior.ColorIndex = 4
Selection.Interior.ColorIndex = xlNone
Case Is = Interior.ColorIndex = 35
Selection.Interior.ColorIndex = xlNone
Case Is = Interior.ColorIndex = 36
Selection.Interior.ColorIndex = xlNone
Case Is = Interior.ColorIndex = 7
Selection.Interior.ColorIndex = xlNone
Case Is = Interior.ColorIndex = 54
Selection.Interior.ColorIndex = xlNone
End Select

' Set range to cells for current month (WHICH IS CELL A3) starting row 20
Set rng = Range(Cells(20, ncol), Cells(lrow, ncol))

' Set Divisor for current month
divisor = Cells(5, ncol)

' Loop through all cells in range
For Each cell In rng

' Check length of cell in column A
If Len(cell.Offset(0, -(ncol - 1))) = 4 Then
' Calculate perecentage
If Application.IsNumber(cell) Then ' Is this cell a number ?

' Calculate percentage
pcnt = (cell / divisor) * 100
cell.Select
' Set colorindex based on percentage
Select Case pcnt
Case Is 100
Selection.Interior.ColorIndex = 4
Case Is = 90
Selection.Interior.ColorIndex = 35
Case Is = 80
Selection.Interior.ColorIndex = 36
Case Is = 70
Selection.Interior.ColorIndex = 7
Case Is = 1
Selection.Interior.ColorIndex = 54
Case Else
Selection.Interior.ColorIndex = 3
End Select

' This colors the blank empty cells
Else
cell.Select
Selection.Interior.ColorIndex = 3

End If
End If
Next cell

End Sub
 
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
count month when date is in day/month/year format ccKennedy Excel Worksheet Functions 6 April 30th 09 03:32 AM
Tell me which "season" (Month/Day through Month/Day) a date(Month/Day/Year) falls in (any year)??? misscrf Excel Discussion (Misc queries) 1 December 14th 07 02:59 PM
trying to get day/month/year froamt while user enters year only RADIOOZ New Users to Excel 3 June 7th 06 05:30 AM
Sumif interior.colorindex condition John Excel Worksheet Functions 7 June 1st 06 01:17 AM
xlNone incorrectly valued? BruceD[_2_] Excel Programming 1 June 11th 04 07:06 PM


All times are GMT +1. The time now is 07:36 AM.

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"