VB Code Help

Get_Involved

Active Member
Joined
Jan 26, 2007
Messages
383
Is there VB Code to get a cell date to change to different colors in this format <= 30,20,14,7] days?
Thanks in Advance
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
you can color a cell based on it's value with conditional formatting, you don't need to code it.
 
Upvote 0
You could just do this with conditional formatting.

If you absolutely want to do it with VBA I would use if statements for your timeframe like:

Code:
if cell.value - ReferenceDate <= 7then
    cell.interior.colorindex = color1number
elseif cell.value - ReferenceDate <= 14 then
    cell.interior.colorindex = color2number
    ......
End if


Where the cell is the cell you're looking to change the color. ReferenceDate is the date you're finding the difference of 30,20,14 etc days from. (I'm not sure if you're doing this from a todays date, or some other reference date).

And the color values are the numbers of the colors you want from: https://msdn.microsoft.com/en-us/vba/excel-vba/articles/colorindex-property
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,106
Members
452,302
Latest member
TaMere

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