VBA Calculate date difference

cortexnotion

Board Regular
Joined
Jan 22, 2020
Messages
150
Office Version
  1. 2013
Platform
  1. Windows
Hi All,

Below is an extract from my current code. After some formulas have been inserted I need to perform the following calculations. Currently, the first condition does not add anything into Column M?

- If Column A does not contains "TCS", Column D has a valid date, Column E is empty and Column F is empty, Then in Column M do Workday Column L Value + 10

OR

- If Column A does contains "TCS", Column D has a valid date, Column E is empty and Column F is empty, Then in Column M add Column L Value.

*Column D,E,F all have formula which returns a date or enters "" in the cell

VBA Code:
With Sheets("DataWork")
.Range("AB3:AB" & LR2).Formula = "=IF(ISNUMBER(E3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(E3,-" & 0 & ",FigWork!$AE$2:$AE$9),WORKDAY(E3,-" & 5 & ",FigWork!$AE$2:$AE$9)),"""")"
    .Range("AC3:AC" & LR2).Formula = "=IF(ISNUMBER(F3),F3,"""")"
    .Range("AD3:AD" & LR2).Formula = "=IF(ISNUMBER(G3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(G3,-" & 5 & ",FigWork!$AE$2:$AE$9),WORKDAY(G3,-" & 5 & ",FigWork!$AE$2:$AE$9)),"""")"
    .Range("AE3:AE" & LR2).Formula = "=IF(ISNUMBER(H3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(H3,-" & 20 & ",FigWork!$AE$2:$AE$9),WORKDAY(H3,-" & 10 & ",FigWork!$AE$2:$AE$9)),"""")"
    .Range("AF3:AF" & LR2).Formula = "=IF(ISNUMBER(I3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(I3,-" & 5 & ",FigWork!$AE$2:$AE$9),WORKDAY(I3,-" & 5 & ",FigWork!$AE$2:$AE$9)),"""")"
    .Range("AG3:AG" & LR2).Formula = "=IF(ISNUMBER(J3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(J3,-" & 5 & ",FigWork!$AE$2:$AE$9),WORKDAY(J3,-" & 5 & ",FigWork!$AE$2:$AE$9)),"""")"
    .Range("AH3:AH" & LR2).Formula = "=IF(ISNUMBER(K3),IF(ISNUMBER(SEARCH(""TCS"",$A3)),WORKDAY(K3,-" & 5 & ",FigWork!$AE$2:$AE$9),WORKDAY(K3,-" & 5 & ",FigWork!$AE$2:$AE$9)),"""")"

    For r = 3 To LR2
        If InStr(Cells(r, 1), "TCS") = 0 And Len(Cells(r, 4)) > 0 And Cells(r, 5) = "" And Cells(r, 6) = "" And _
        Application.Evaluate("NETWORKDAYS(L" & r & ",TODAY(),FigWork!$AE$2:$AE$9)-SIGN(NETWORKDAYS(L" & r & ",TODAY(),FigWork!$AE$2:$AE$9))") > 10 Then
            Cells(r, 13).Value = Application.Evaluate("WORKDAY(L" & r & "," & 10 & ",FigWork!$AE$2:$AE$9),"""")")
        ElseIf InStr(Cells(r, 1), "TCS") > 0 And Cells(r, 4) > 0 And Cells(r, 5) = "" And Cells(r, 6) = "" Then
            Cells(r, 13).Value = Cells(r, 12).Value
    End If
    Next r

End With


Many thanks!
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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