Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Apply filter and delete rows thru Messege Box

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13

    Apply filter and delete rows thru Messege Box

    Hi Frineds,

    My macro is not working, i need to apply filter thur message box and delete after the given date rows.I have attached the macro sheet for your reference .

    Kindly help to correct the same.

    Regards,

    Prabhu
    Attached Files Attached Files

  2. #2
    Senior Member alansidman's Avatar
    Join Date
    Apr 2012
    Posts
    125
    Rep Power
    13
    Try this:

    Code:
    Sub MYFILTER()
    Dim W1Startdate As Date
    W1Startdate = InputBox("Please Enter the Start Data in DD/MM/YYYY format")
    range("A2:T" & range("A1").End(xlDown).Row).AutoFilter Field:=7, Criteria1:=">" & W1Startdate
    'range("A4:T" & range("A2").End(xlDown).Row).SpecialCells(12).EntireRow.Delete
    
    
    End Sub

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Hi,

    I tried, but it is not deleting the record after the given date. i.e it is struck on the filter.

    Code:
    Sub MYFILTER()
    Dim W1Startdate As Date
    W1Startdate = InputBox("Please Enter the Start Data in DD/MM/YYYY format")
    range("A2:T" & range("A1").End(xlDown).Row).AutoFilter Field:=7, Criteria1:=">" & W1Startdate
    range("A3:T" & range("A2").End(xlDown).Row).SpecialCells(12).EntireRow.Delete
    End Sub
    Kindly help
    Last edited by Excel Fox; 11-01-2014 at 09:16 PM. Reason: Code Tag added

  4. #4
    Senior Member alansidman's Avatar
    Join Date
    Apr 2012
    Posts
    125
    Rep Power
    13
    Try this:

    Code:
    Option Explicit
    
    Sub NewDelete()
        Dim W1Startdate As Date
        W1Startdate = InputBox("Please Enter the Start Data in DD/MM/YYYY format")
        Dim lr As Long
        lr = Range("G" & Rows.Count).End(xlUp).Row
        Dim i As Long
        
        Application.ScreenUpdating = False
        For i = lr To 3 Step -1
        If Range("G" & i) >= W1Startdate Then
        Range("G" & i).EntireRow.Delete
        End If
        Next i
        
        Application.ScreenUpdating = True
        MsgBox "task complete"
    
    End Sub

    Please use code tags when posting VBA Code in the forum. It makes for easier reading and is a forum standard.

  5. #5
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    Thanks it is working!

    But it is taking huge amount of time when we delete larger data. i think it is deleting row by row.

    can we make change to delete the enter in one short now like deleting manually?

  6. #6
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    Try

    Code:
    Sub MYFILTER()
        
        Dim W1Startdate As String
        Dim dtFilter    As Date
        
        W1Startdate = Application.InputBox("Please Enter the Start Data in DD/MM/YYYY format", Type:=2)
        If W1Startdate = "False" Then Exit Sub
        
        If IsNumeric(Replace(W1Startdate, "/", vbNullString)) Then
            dtFilter = DateSerial(Split(W1Startdate, "/")(2), Split(W1Startdate, "/")(1), Split(W1Startdate, "/")(0))
            Range("A2:T" & Range("A1").End(xlDown).Row).AutoFilter Field:=7, Criteria1:=">" & dtFilter
            Range("A3:T" & Range("A2").End(xlDown).Row).SpecialCells(12).EntireRow.Delete
            If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        End If
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  7. #7
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    No Sir,

    It is not deleting.

  8. #8
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Any error ? how many rows of data you have ?
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  9. #9
    Member
    Join Date
    Aug 2011
    Posts
    54
    Rep Power
    13
    I found 2 issues:

    1.It is taking MM/DD/YYYY instead of DD/MM/YYYY.

    2. If the input dates between 1- 10 example 08/10/2014(10th Aug 2014) it is deleting correctly but the input dates between 11-31 example 08/15/2014 it is not taking any action.

    I have attached the data for your reference. Kindly help to correct the same.

    Regards,

    Prabhu
    Attached Files Attached Files

  10. #10
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    It's working here. You need to enter the date in dd/mm/yyyy format.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Delete Rows Based on Conditions
    By AbiG2009 in forum Excel Help
    Replies: 6
    Last Post: 12-26-2018, 01:24 PM
  2. search for data and delete rows containing it
    By RickStewart in forum Excel Help
    Replies: 2
    Last Post: 02-24-2014, 09:12 PM
  3. Delete blank rows
    By dhivya.enjoy in forum Excel Help
    Replies: 5
    Last Post: 10-23-2013, 10:04 PM
  4. Delete Rows
    By ayazgreat in forum Excel Help
    Replies: 2
    Last Post: 12-13-2012, 11:48 AM
  5. Delete Empty Rows
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 04-28-2011, 02:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •