Solved

Excel 2010 delete rows with a dates less than last working day

Posted on 2014-03-07
4
568 Views
Last Modified: 2014-03-07
Can an expert provide me with VBA code that will delete rows with a dates less than last working day

i.e. if today is 07-Mar-14 ...Cells in column A dated 05-Mar-14 or less delete Keep only 06-Mar-14

On Monday 10-Mar-14 keep only 07-Mar-14

Thanks
0
Comment
Question by:Jagwarman
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
HI,

pls try

Sub macro()
lstRow = Range("A" & Cells.Rows.Count).End(xlUp).Row
For Idx = lstRow To 1 Step -1 ' change 1 to the first row with dates
    If Cells(Idx, 1) < Application.WorksheetFunction.WorkDay(Date, -1) Then
        Cells(Idx, 1).EntireRow.Delete
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Comment

by:Jagwarman
Comment Utility
Hi Rgonzo1971 I am never sure what Dims to use?
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

Sub macro()
Dim lstRow As Long, Idx As Long
lstRow = Range("A" & Cells.Rows.Count).End(xlUp).Row
For Idx = lstRow To 1 Step -1 ' change 1 to the first row with dates
    If Cells(Idx, 1) < Application.WorksheetFunction.WorkDay(Date, -1) Then
        Cells(Idx, 1).EntireRow.Delete
    End If
Next
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:Jagwarman
Comment Utility
Brilliant thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now