none
Filter Data Need to Remove Code Error RRS feed

  • Question

  • i am using below code for filter data remove  in excel but I am getting run time error 1004

    Sub Remove()
    
        'Last Row
            lrow = Range("A" & Rows.Count).End(xlUp).Row
        If lrow = 1 Then ' Change 1 to your header row number
                ' MsgBox "No Data available based on your current filter"
        Selection.AutoFilter
        Exit Sub
            End If
                With ActiveSheet.AutoFilter.Range
            'First Row
            frow = .Offset(1).Resize(.Rows.Count - 1, .Columns.Count).SpecialCells(xlCellTypeVisible).Row
        End With
        
        Rows(frow & ":" & lrow).Select
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Delete Shift:=xlUp
        Selection.AutoFilter
    End Sub

    Sub Remove()
    
       With ActiveSheet.AutoFilter.Range
             'First Row
                'frow = .Offset(1).Resize(.Rows.Count - 1, .Columns.Count).SpecialCells(xlCellTypeVisible).Row
         End With
         'Last Row
            lrow = Range("A" & Rows.Count).End(xlUp).Row
             
         Rows(frow & ":" & lrow).Select
         Selection.SpecialCells(xlCellTypeVisible).Select
         Selection.Delete Shift:=xlUp
         
    End Sub


    DushYant'


    • Edited by DushYant P Monday, September 18, 2017 8:28 AM
    • Moved by Bill_Stewart Tuesday, November 7, 2017 9:49 PM Move to more appropriate forum
    Monday, September 18, 2017 8:22 AM

All replies

  • Sorry but this is not a VBA forum.  You will need to post in the Excel VBA Developers forum for help with VBA.

    Be sure to post the complete error message as just the error is of no help.


    \_(ツ)_/

    Monday, September 18, 2017 9:27 AM
  • You can decode runtime errors at a command prompt like this:'

    net helpmsg 1004


    \_(ツ)_/

    Monday, September 18, 2017 9:28 AM
  • Hi DushYant ,

    I find that you posted the issue in incorrect forum.

    and this thread is now moved to the correct forum.

    so sorry for late response. I suggest you to post the issue in correct forum from next time so you can get response as soon as possible.

    now if we talk about the error.

    you got error 1004.

    I suggest you to apply the filter and then run the code.

    currently it is not able to find the filter.

    I try to add the  filter and then run the code.

    code runs successfully.

    let us know , if your issue is solved.

    if your issue is already solve then try to post the solution and mark it as an answer.

    if your issue is still exist then try to refer this suggestion to solve the issue.

    if you think that this suggestion can solve the issue then mark this suggestion as an answer.

    it will help us to close this thread.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 8, 2017 5:48 AM
    Moderator