Hi
I am new to VBA programming. I am looking to add a macro that does as below:
compares the start date if it is greater than 30 days, delete the entire row.
Please find attached the sample datasheet.
Thanks
Hi
I am new to VBA programming. I am looking to add a macro that does as below:
compares the start date if it is greater than 30 days, delete the entire row.
Please find attached the sample datasheet.
Thanks
Hi try dis code in sample file
![]()
Sub Delt() Dim r As Long r = Range("A" & Rows.Count).End(xlUp).Row For i = r To 2 Step -1 If Range("D" & i).Value - Range("C" & i).Value > 30 Then Range("D" & i).EntireRow.Delete Next i End Sub
option:
![]()
Sub test() Dim lrow As Long On Error Resume Next lrow = Cells(Rows.Count, 1).End(xlUp).Row With Range("f2:f" & lrow) Application.ScreenUpdating = 0 .Value = "=IF(D2-C2>30,1,"""")" .SpecialCells(xlCellTypeFormulas, xlNumbers).EntireRow.Delete .Clear Application.ScreenUpdating = 1 End With End Sub
What are D2 and C2 here???? IF this is calculation the diffrence between start and finish dates, thats not what I wanted. I wanted to see if the start date which is column C is older than 30 days then I wanted to delete the entire row.
Please advice, thanks
ok, so I assume we compare today's date. Then it could be done this way:
![]()
Sub test() Application.ScreenUpdating = 0 With ActiveSheet.UsedRange .AutoFilter 3, "<" & CLng(DateAdd("d", -30, Date)) If Cells(Rows.Count, 3).End(xlUp).Row > 1 Then .Offset(1).EntireRow.Delete .AutoFilter End With Application.ScreenUpdating = 1 End Sub
THanks very much, its working great
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks