VBA to calculate aging of workorders

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
197
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a spreadsheet of open workorder and am looking to create an aging table to alert staff when the order is over 2 weeks and still open, then 4 weeks, then 60 and 90+days from the date of creation.
Col A W/O# | Date Created | Date Planned | Date Completed | Aging Alert
1030111123 12/1/2024 1/27/2025 (todays date 3/11/25) >90days
1030235443 3/1/2025 4/1/2025 (todays date 3/11/25) <14 days
 
Hi,

You can check the below option :
Book2 (version 1).xlsb
ABCDE
1Col A W/O#Date CreatedDate PlannedDate CompletedAging Alert
2103011112301/12/202427/01/202511/03/2025> 4 Weeks
3103023544301/03/202501/04/202511/03/2025In time
Sheet4
Cell Formulas
RangeFormula
E2:E3E2=LET(duration,D2-C2+1,IFS(duration>90,"> 90 days",duration>60,"> 60 days",duration>28,"> 4 Weeks",duration>14,"> 2 Weeks",duration<=14,"In time"))
 
Upvote 0
Hi,

You can check the below option :
Book2 (version 1).xlsb
ABCDE
1Col A W/O#Date CreatedDate PlannedDate CompletedAging Alert
2103011112301/12/202427/01/202511/03/2025> 4 Weeks
3103023544301/03/202501/04/202511/03/2025In time
Sheet4
Cell Formulas
RangeFormula
E2:E3E2=LET(duration,D2-C2+1,IFS(duration>90,"> 90 days",duration>60,"> 60 days",duration>28,"> 4 Weeks",duration>14,"> 2 Weeks",duration<=14,"In time"))
Is this the VBA code I can copy and run? My boss changed to wanting one column per bucket so for <2weeks column S, <30 days Column T etc. how can I adjust for this change?
 
Upvote 0
Based on your office version, this was a dynamic formula and not a VBA. You can share a small sample for your requirement stating the required results and me or someone else will provide you with a formula.
 
Upvote 0
Ok so I tried modifing the formula to:
LET(duration, (TODAY()-$O2)+1,IFS(duration>90,">90 Days",duration>60,"> 60 Days",duration>30,"> 30 Days",duration<=30,"In time", duration<=7,"Current"))

Col O is the creation date the other dates do not matter for the aging buckets. Example of what I am looking for:
 

Attachments

  • Aging Example.jpg
    Aging Example.jpg
    49.4 KB · Views: 6
Upvote 0
You can try the below :

Book3
OPQRSTUYZAAAB
1Created OnCreatedPlanningChanged OnChanged ByPlant for WorkCentCity1-3031-6061-90Over 90
206/03/2025RFCUSAISU931006/03/2025U4369729310BETHELIn time   
314/02/2025RFCUSAISU931021/02/2025IJ3548639310HIRAM > 30 Days  
413/02/2025RFCUSAISU931016/02/20251374229310GORHAM > 30 Days  
515/01/2025RFCUSAISU931004/02/2025584589310LIMERICK  > 60 Days 
617/12/2024RFCUSAISU931004/02/20251-13548639310PARSONSFIELD   > 90 Days
Sheet1
Cell Formulas
RangeFormula
Y2:AB6Y2=IFERROR(LET(result,LET(duration,(TODAY()-$O2)+1,IFS(duration>90,"> 90 Days",duration>60,"> 60 Days",duration>30,"> 30 Days",duration<=30,"In time",duration<=7,"Current")),IFS(AND(result="In time",COLUMNS($Y$1:Y$1)=1),"In time",AND(result="> 30 Days",COLUMNS($Y$1:Y$1)=2),"> 30 Days",AND(result="> 60 Days",COLUMNS($Y$1:Y$1)=3),"> 60 Days",AND(result="> 90 Days",COLUMNS($Y$1:Y$1)=4),"> 90 Days")),"")
 
Upvote 0
Can i copy the formula to VBA? I am running VBA with command buttons as I am not the only employee that will utilitze this report.
Thank you for all your help.
 
Upvote 0
@Sanjeev1976 sorry to intervene,
@fvisions , Please try this,
VBA Code:
Sub Update_Aging()
    Dim ws As Worksheet, lastRow As Long, i As Long, j As Long, dur As Long
    Dim category As String, ageCols As Variant
    Set ws = ActiveSheet
    lastRow = ws.Cells(ws.Rows.Count, "O").End(xlUp).Row
    ageCols = Array("Current", "In time", "> 30 Days", "> 60 Days", "> 90 Days")

    For i = 2 To lastRow
        dur = IIf(IsDate(ws.Cells(i, 15)), Date - ws.Cells(i, 15) + 1, 0)
        category = Choose(IIf(dur <= 7, 1, IIf(dur <= 30, 2, _
                    IIf(dur <= 60, 3, IIf(dur <= 90, 4, 5)))), _
                    ageCols(0), ageCols(1), ageCols(2), ageCols(3), ageCols(4))

        For j = 25 To 28
            ws.Cells(i, j).Value = IIf((j - 24) = _
                IIf(category = "Current", 1, IIf(category = "In time", 1, _
                IIf(category = "> 30 Days", 2, IIf(category = "> 60 Days", 3, 4)))), category, "")
        Next j
    Next i
    
End Sub
 
Upvote 0
Solution

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