473,441 Members | 3,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Conditional formatting and Date Difference in VBA

Hi,

I am creating a macro in Excel to extract some information from Master excel.

In Master sheet, have some data with the column- 'Target dates' (list of Dates) in it.

I want to compare Target dates with the current date and if the Target dates already breached the current date, then should be highlighted in red.

If Target date has 10 days from the current date, then should be highlighted in amber.

If Target date has more than 10 days from the current date, then should be highlighted in green.

Please help me with the codes.
Dec 19 '19 #1
4 3137
twinnyfo
3,653 Expert Mod 2GB
abhivishak,

Welcome to Bytes!

I moved your thread to the appropriate forum.

Assuming your Target Date is in Column A, your formulas within Conditional Formatting (for respective Red, Yellow and Green) would look like this:
Expand|Select|Wrap|Line Numbers
  1. =A1<=TODAY()
  2. =A1<=TODAY()+10
  3. =A1>TODAY()+10
Just set your colors as desired in the Conditional Formatting Editor.

Hope this hepps!
Dec 19 '19 #2
SioSio
272 256MB
When the target date is listed in the column after A2
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim MaxRow As Integer
  3. MaxRow = Range("A1").End(xlDown).Row
  4. For i = 2 To MaxRow
  5.     If DateDiff("d", Now, Cells(i, 1).Value) < 0 Then
  6.         Cells(i, 1).Font.Color = RGB(255, 0, 0)
  7.     ElseIf DateDiff("d", Now, Cells(i, 1).Value) = 10 Then
  8.         Cells(i, 1).Font.Color = RGB(234, 147, 10)
  9.     ElseIf DateDiff("d", Now, Cells(i, 1).Value) >= 10 Then
  10.         Cells(i, 1).Font.Color = RGB(0, 128, 0)
  11.     End If
  12. Next i
  13.  
Dec 23 '19 #3
Thanks twinnyfo. But I expect the result through VBA.

Thanks Sio Sio. Let me try this one.
Dec 23 '19 #4
twinnyfo
3,653 Expert Mod 2GB
Is there a “requirement” to do something in VBA? It seems to be the more difficult route when conditional formatting is built into Excel.

Unless, of course, I am missing something about your project.
Dec 23 '19 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: moon | last post by:
Hi all, I want to write an expression that would color code a set of dates. I have two fields in a continuous form called "beginning date" and "end date" . I want to change the color of a record...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
by: Sara | last post by:
The problem: Conditional formatting bold, red when field Value < date() sets the field background to white - always - whether condition is met or not. I want the field unfilled and just red/bold...
5
by: jodyblau | last post by:
I am trying to do some conditional formatting with a textbox and I am not able to quite get it. Here is the setup: My record includes a textbox called and two checkboxes the first called ...
2
by: OdAwG | last post by:
Hello Again Access GURU's, Need some help with Conditional Formatting and datediff. What I am trying to do is the following: I have three text boxes with dates in them and what I want to do...
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: ApexData | last post by:
In a Continuous form, I want to use Conditional Formatting to change the background color of a date field based on a condition. 1-The color chart in the CF menu option offers limited colors. How...
2
by: keri | last post by:
I would like to set up conditional formatting on a form. One of the fields on the form is a date (). If the calldate field is over 365 days ago I would like all the other fields on the form line...
10
by: afromanam | last post by:
Regards, Please help What I'm trying to do is this: (and I can't use reports since I must export to Excel) I export some queries to different tabs in an excel workbook I then loop through...
2
by: fredmart | last post by:
Hi, I'm having problems finding a way to apply conditional formatting based on comparing the text contents of two fields in two different tables. What I'd like to do: I've got two tables that...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.