Populate a cell with text and formatting based on a whether a date field falls within a date range

MLC1980

New Member
Joined
Oct 1, 2024
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I'm trying to automatically populate a specific cell with some text and some formatting based on whether a date falls with a date range. To try and explain this further, these are the fields I'm looking at:

Cell G1 = Start Date
Cell G2 = End Date
Cell B13 currently has an 'IF' statement to apply the same date as Cell G1 (This is week 1)
Cells B14:B64 are weeks 2 to 52 and populate by applying 7 days to the previous date (e.g. cell B14 is B13 plus 7 days, cell B15 is B14 plus 7 days)
Cell C13:C64 are the cells that I want to automatically populate.

The rule I want is that if Cells B13:B64 fall within the start and end date range in cells G1 and G2 then populate Cell C13:C64 with "ML/AL", I also want the cells formatted with a fill colour of purple (R112,G48,B160) and a font colour of white. This would be the same for the rest of the weeks.

Is this possible with VBA?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Should be doable with or without vba. Perhaps simpler to use a formula and a CF rule? Using this formula
=IF(AND(B1>$G$1,B1<$G$2),"ML/AL","") in C1 and C2 and date range in G1 and G2 I get this result with these dates in B1 and B2:
1729873896969.png


With the menu selections (shown as light green)
1729874016560.png

The rule is
1729874090790.png
 
Upvote 0
Solution
@Micron, thanks for your solution. I just altered the formula slightly to account for including the start and end date:
Excel Formula:
=IF(AND(B13>=$G$1,B13<=$G$2),"ML/AL","")

Many thanks
 
Upvote 0
Glad I could help & thanks for the recognition. I don't understand what you mean about the adjustment though since we both used $G$1 and $G$2 for those dates. What you posted looks the same to me except you started with row 13 for B column values while I started with B1.
 
Upvote 0

Forum statistics

Threads
1,223,847
Messages
6,174,992
Members
452,598
Latest member
jeffreyp

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
Back
Top