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).
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.