Solved

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

Posted on 2014-03-07
4
598 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 49

Expert Comment

by:Rgonzo1971
ID: 39912020
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
ID: 39912027
Hi Rgonzo1971 I am never sure what Dims to use?
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39912033
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
ID: 39912064
Brilliant thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA - Public declaration of variables 3 46
Excel Formula 4 28
Most Consistent Performer 4 21
Excel printing page management 2 21
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

16 Experts available now in Live!

Get 1:1 Help Now