Want to Delete Date and Data

xeeshanxp

New Member
Joined
Jun 22, 2010
Messages
25
I have excel sheet which got 3500 lines of data. I want to delete rows which got date less than 30-06-2010.This macro deleteing some dates but not all of them i change the value of last to 400 but it just delete few in that iteration


Sub Test()
Dim last As Integer
Dim DaTD As Date
DaTD = DateSerial(2010, 6, 30)

last = 100

For c = 1 To last
If Range("L" & c).Value <= DaTD Then
Rows(c).EntireRow.Delete

End If

Next c


End Sub
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
You need to loop backwards. Try

Code:
Sub Test()
Dim last As Long, c As Long
Dim DaTD As Date
DaTD = DateSerial(2010, 6, 30)

last = Range("C" & Rows.Count).End(xlUp).Row

For c = last To 1 Step -1
    If Range("L" & c).Value <= DaTD Then
        Rows(c).EntireRow.Delete

    End If

Next c


End Sub
 

Dan44

New Member
Joined
Jul 28, 2010
Messages
2
If you've got 3500 lines of data then you need to change the "last" variable

last = 3500

The code was only looping 100 times then stopping, so you had 3400 lines still unchecked.
 

xeeshanxp

New Member
Joined
Jun 22, 2010
Messages
25
No that code is not working at all now its not deleting a single row


Dan i know this thanks for letting me know
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

Sorry, it should be

Rich (BB code):
last = Range("L" & Rows.Count).End(xlUp).Row
 

xeeshanxp

New Member
Joined
Jun 22, 2010
Messages
25
I also want to delete some more rows containing texts in column F
What code should i used
 

xeeshanxp

New Member
Joined
Jun 22, 2010
Messages
25
Thanks its sorted ;)

I am using this code where K is column


ElseIf LCase(Left$(Range("K" & c).Value, 5)) = "khan" Then
Rows(c).EntireRow.Delete
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,567
Messages
5,512,096
Members
408,880
Latest member
FrankHH

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top