PDA

View Full Version : VBA code to count number of only weekdays between 2 dates



krishak77
07-09-2018, 07:32 AM
Hi All,

I need VBA code for the below situation.

i have 2 days in 2 columns

ColumnA ColumnB
09-July-2018 06-July-2018
09-July-2018 04-July-2018

So if Column B date is less than 2 working days, then the complete row should be delete.

Regards,
Anantha Krishna

mana
07-09-2018, 08:59 AM
Sub test()

Application.ScreenUpdating = False

With Cells(1).CurrentRegion.Columns(3)
.Formula = "=networkdays(b1,a1)"
.Value = .Value
End With

Rows(1).Insert
With Cells(1).CurrentRegion.Columns(3)
.AutoFilter 1, "<2"
If .SpecialCells(xlCellTypeVisible).Count > 1 Then
.Offset(1).EntireRow.Delete
End If
.AutoFilter
.ClearContents
End With
Rows(1).Delete

End Sub