VBA to work out if a date is overdue

ryandonovan22

New Member
Joined
Sep 17, 2015
Messages
36
Hello,

I need a Macro to work out if a range of dates are overdue based on comparing expected delivery date against todays date

There could be any number of rows each week so it will have to perform the calculation over an undetermined range.

If I was to produce an if statement within the cell this is what I would use =if(G2<TODAY(),"Overdue",OK") and drag the formula down
<today(),"overdue","ok") range.

for the purpose of the VBA formula, this data will need to be placed into column N

Thanks,
Ryan.</today(),"overdue","ok")>
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Looks like your formula got cut off. Try putting spaces around any < . The forum will sometime think you are using HTML and drop what is after the < .
 
Upvote 0
Try this:

Code:
Option Explicit


Sub Overdue()
    Dim i As Long, lr As Long
    lr = Range("G" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        If Range("G" & i) < Date Then
            Range("N" & i) = "Overdue"
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this.

Code:
Sub isoverdue()
Dim lr As Long
lr = Cells(Rows.Count, "G").End(xlUp).Row
For x = 2 To lr
    If Cells(x, "G") < Date Then
        Cells(x, "N") = "Overdue"
    Else
        Cells(x, "N") = "OK"
    End If
Next x
End Sub
 
Upvote 0
Try this:

Code:
Option Explicit


Sub Overdue()
    Dim i As Long, lr As Long
    lr = Range("G" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        If Range("G" & i) < Date Then
            Range("N" & i) = "Overdue"
        End If
    Next i
    Application.ScreenUpdating = True
End Sub

I already have an entire sub completing all of the below.

How do I add this macro in without getting error (which I am currently getting)


Code:
Sub TidyAll()
'Delete columns
Columns(5).EntireColumn.Delete
Columns(5).EntireColumn.Delete
Columns(6).EntireColumn.Delete
Columns(6).EntireColumn.Delete
Columns(6).EntireColumn.Delete

' remove the leading zeros on part numbers
Dim myCell As Range
Dim myRng As Range
Dim iCtr As Long
With Worksheets("Raw Data")
Set myRng = .Range("C1", .Cells(.Rows.Count, "C").End(xlUp))
For Each myCell In myRng.Cells
For iCtr = 1 To Len(myCell.Value)
If Mid(myCell.Value, iCtr, 1) <> "0" Then
Exit For
End If
Next iCtr
myCell.Value = Mid(myCell.Value, iCtr)
Next myCell
End With

'Insert columns
Range("A1").EntireColumn.Insert
Range("A1").Select
ActiveCell.FormulaR1C1 = "Owner"
Range("N1").Select
ActiveCell.FormulaR1C1 = "Status"
Range("O1").Select
ActiveCell.FormulaR1C1 = "Confirmed Delivery Date"
Range("P1").Select
ActiveCell.FormulaR1C1 = "Outstanding Actions?"
Range("Q1").Select
ActiveCell.FormulaR1C1 = "Comments"
Range("R1").Select
ActiveCell.FormulaR1C1 = ""
Range("S1").Select
ActiveCell.FormulaR1C1 = ""

'Change cell color
Range("A1").Interior.ColorIndex = 6
Range("N1:S1").Interior.ColorIndex = 43

'Auto Filter sheet
Range("A1:S1").AutoFilter

'Center text
With Sheets("Raw Data")
.Range("A:S").HorizontalAlignment = xlCenter
End With
'Add boarders around cells
 With ActiveSheet.UsedRange.Borders
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    
'Sort in ascending order
Range("A:S").Sort _
Key1:=Range("F1"), Header:=xlYes

'Looks up buyer linked to particular supplier.
With Sheets("Raw Data")
    With .Range("A2:A" & .Range("F" & .Rows.Count).End(xlUp).Row)
        .Formula = "=VLOOKUP(F2,'" & Sheets("Suppliers & Owners").Name & "'!$A$2:$B$51,2,0)"
        .Value = .Value
        .Replace "0", "Unallocated", LookAt:=xlWhole
    End With
End With

' Provides Overdue or OK status
 

' Set columns to auto fit
Worksheets("Raw Data").Range("A:S").Columns.AutoFit

MsgBox "Open Order Book Formatting Complete!"
End Sub
 
Last edited by a moderator:
Upvote 0
What does your new code look like. Where did you insert the code provided. What is the error message you are receiving. When you get the error message, click on Debug and then tell us which line of code is highlighted. We really need to see what you see in order to analyze and help. Mind reading is not a specialty that we employ here.:)
 
Upvote 0
What does your new code look like. Where did you insert the code provided. What is the error message you are receiving. When you get the error message, click on Debug and then tell us which line of code is highlighted. We really need to see what you see in order to analyze and help. Mind reading is not a specialty that we employ here.:)

I managed to get both Macros to function, although one was more successful than the other but neither worked 100%

I removed the Sub and End sub and inserted it into my existing sub.

This macro worked, but only displayed "OK" even when there should have been "Overdue" appearing

Code:
Dim lr As Long
lr = Cells(Rows.Count, "G").End(xlUp).Row
For x = 2 To lr
    If Cells(x, "G") < Date Then
        Cells(x, "N") = "Overdue"
    Else
        Cells(x, "N") = "OK"
    End If
Next x
 
Last edited:
Upvote 0
You need to tell us what is not working. Telling us it doesn't work is no help. What is missing?
 
Upvote 0
Alan - your macro didn’t work. It ran fine but put no results in column N

Scott’s macro worked, but not properly. Instead of putting “overdue” where the date in Column G was <. Today’s date, it just put “OK” in all of the cells in column N
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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