Conditional format based on week number

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
Hi all!

I don't know whether this is possible, but I would like to conditionally format a group of cells so that if a marked cell is overdue, the colour changes to red, if it is within 2 weeks prior it is yellow, more than 2 weeks green.

Basically, my sheet has 54 columns, columns A & B contain equipment data, the rest are numbered from 1 to 52, to represent the week number. If a cell contains 'C', then that indicates that the equipment is due for calibration in that week. If there is no entry in the cell, then the colour doesn't change, otherwise the formatting needs to be as displayed above.

I've had a play around, but I can't figure how to do the formatting by week number - ideally I would like to do this without using VBA, but if that isn't possible then a VBA solution would be fine.

Anyone have any thoughts?

Regards,

Mark
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825
What definition of week number are you using, i.e. on what date does week 1 start?

Assuming you are using excel's WEEKNUM function then if you select your data range, I'm assuming it's something like

=C2:BB100

Format Conditional Formatting

Condition 1
"formula is" =(INT((TODAY()-WEEKDAY(TODAY())-DATE(YEAR(TODAY()),1,1))/7)+2>C$1)*(C2="C")
format red

Condition 2
"formula is" =(INT((TODAY()-WEEKDAY(TODAY())-DATE(YEAR(TODAY()),1,1))/7)+4>C$1)*(C2="C")
format yellow

Condition 3
"formula is" =C2="C"
format green
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
48,590
Office Version
  1. 365
Platform
  1. Windows
mplees

See if this is headed in the right direction.

I have just shown a small section of the sheet.

1. AK9: =WEEKNUM(TODAY())
This is the week number of today's date, though you would no doubt house this elsewhere on your sheet.
2. The conditional formatting in AI4 is:
Condition1|Formula is: =(AI4="C")*((AI$1-$AK$9)<0)
Condition 2|Formula is: =(AI4="C")*((AI$1-$AK$9)<=2)
Condition 3|Formula is: =(AI4="C")*((AI$1-$AK$9)>2)
Formatting can be 'Painted' to other cells.
Mr Excel.xls
AIAJAKALAMANAOAPAQAR
133343536373839404142
2
3
4CCCCCCC
5
6
7Current
8Weeknum
936
10
Week Numbers
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
Hi Barry,

For simplicity's sake, I'm using absolute week numbers, & always assuming that week 1 commences on January 1st, rather than using ISO definition or anything else.

Regards,

Mark
 

barry houdini

MrExcel MVP
Joined
Mar 23, 2005
Messages
20,825

ADVERTISEMENT

Perhaps try Peter's approach, more efficient than mine, but instead of =WEEKNUM(TODAY()) in AK9 use

=CEILING((TODAY()-DATE(YEAR(TODAY()),1,0))/7,1) to give the week number based on your definition


[although I think the 3rd condition could simply be =AI4="C"]
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
Barry, Peter:

Many thanks for your suggestions, both of which work well. I opted for Peter's conditional formatting, but using Barry's formula that didn't use WEEKNUM, as this means I don't have to use the Analysis Pak add-in.

Thank you both for your valued input.

Regards,

Mark
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351

ADVERTISEMENT

Hi again....

a further thought on a refinement that could be very useful in my application. Is it possible to trigger a messagebox when opening the sheet to indicate which items are overdue? In effect, if the cell is red, then open a message box or series of messageboxes.

This would only need to run once on opening the sheet - is this possible?

Regards,

Mark
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
Hi again!

I've been experimenting a little, & by trial and error came up with the following code:

If Worksheets("sheet1").Range("a1:a10").Interior.ColorIndex = 3 Then
MsgBox "Overdue!"
Else

End If


....which sort of works, but only if the whole range colour is red. How can I look at a range of cells, but trigger the message box if only one cell is red?

All help gratefully received!

Regards,

Mark
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
OK, a little more progress! The following code almost does what I want:

Dim vCell As Range
Range("C1:C10").Select

For Each vCell In Selection
If vCell.Interior.ColorIndex = 3 Then
MsgBox vCell.Address

End If
Next

....all I need to figure out is how to return the corresponding value in column A to a msgbox. For example, if cell C5 is red, then how do I pass the value in A5 to the msgbox? Would I need to do a Vlookup or something similar?

Regards,

Mark
 

mplees

Active Member
Joined
Feb 6, 2006
Messages
351
Figured it!

Dim vPt As String
Dim vCell As Range
Range("C1:C10").Select

For Each vCell In Selection
If vCell.Interior.ColorIndex = 3 Then
MsgBox vCell.Address
vPt = Right((vCell), 2)
MsgBox Range("A" & vPt).Value
End If
Next

...seems to work

Regards,

Mark
 

Watch MrExcel Video

Forum statistics

Threads
1,130,342
Messages
5,641,583
Members
417,223
Latest member
jelena_

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
Top