SOLVED

create VBA function to highlight dates

Copper Contributor

I have a spreadsheet that needs to have a date function inserted. Our business has to do reports for clients on a regular basis and I need to highlight upcoming report dates for specific clients. I'm not a regular user of VBA so it is hard for me even when it may be the simplest of solutdates screenshot.jpgions for someone else.

10 Replies

@JohnD1954 

It may be possible to do this without VBA, using conditional formatting instead. Could you tell us which cells you want to be highlighted, and under which conditions?

I've tried conditional formatting and there isn't enough flexibility.
It takes 30 days to set up all the different responses required to do a report so I need to know 30 days ahead of time of any report coming due. I also need to know of any dates that come short of that time period, i.e., somewhere in between the 30 days and due date. Third option needs to be where a report is past due.
best response confirmed by JohnD1954 (Copper Contributor)
Solution

@JohnD1954 

It shouldn't be difficult to do that using conditional formatting.

Select the entire range with the dates that you want to highlight.

 

On the Home tab of the ribbon, select Conditional Formatting > New Rule...

Select 'Format only cells that contain'.

Leave the first drop-down set to 'Cell Value'.

Select 'equal to' from the second drop-down.

Enter the formula =TODAY()+30 in the box next to it.

Click Format...

Activate the Fill tab.

Select a color, for example yellow.

Click OK, then click OK again.

 

Repeat the above steps, but with 'less than' instead of 'equal to'.

Use the same formula =TODAY()+30 and select a different color, for example orange.

 

Finally, repeat them again, with 'less than'.

Use the formula =TODAY() and select yet another color, for example red.

I shall try and let you know. I didn't know that you can set up conditional formatting more than once on the same selection. Thank you

@JohnD1954 unfortunately it doesn't work. 
Conditional Format1.jpg
it needs a secondary code to limit range plus it isn't being selective as it's highlighting everything even those that don't fit range.

@JohnD1954 

The formulas should not have quotes around them, and begin with =

For example, =TODAY()+30 instead of "TODAY()+30"

I didn't insert the quotes, purely Excel function

@JohnD1954 

Excel added the quotes, but that means the rule won't work as intended.

that's why I'm thinking it may be better and more comprehensive to use VBA. Unfortunately, I don't know much about coding.
Hi JohnD,
I concur with others, while I am an avid VBA User, you should be able to do this without. I will say this about excel, columns are your friend! what I mean is, there are 16000 columns on an excel worksheet.. I have yet to see a data set that has 16000 columns. Utilize them to build your indicators. one column for past due, one column for almost due (0-30 days) and one column for okay.
Then you can take a fourth column to put an if statement in to identify which one it is with a letter.
do your conditional formatting off the column with the If and then Hide those columns.
It is not nearly as elegant as doing the entire formula in conditional formatting (which you should be able to work out) but it's a heck of a lot easier to understand..
1 best response

Accepted Solutions
best response confirmed by JohnD1954 (Copper Contributor)
Solution

@JohnD1954 

It shouldn't be difficult to do that using conditional formatting.

Select the entire range with the dates that you want to highlight.

 

On the Home tab of the ribbon, select Conditional Formatting > New Rule...

Select 'Format only cells that contain'.

Leave the first drop-down set to 'Cell Value'.

Select 'equal to' from the second drop-down.

Enter the formula =TODAY()+30 in the box next to it.

Click Format...

Activate the Fill tab.

Select a color, for example yellow.

Click OK, then click OK again.

 

Repeat the above steps, but with 'less than' instead of 'equal to'.

Use the same formula =TODAY()+30 and select a different color, for example orange.

 

Finally, repeat them again, with 'less than'.

Use the formula =TODAY() and select yet another color, for example red.

View solution in original post