Closed Thread
Results 1 to 6 of 6

Delete Rows After a filter

Hybrid View

koda86 Delete Rows After a filter 11-24-2008, 01:59 AM
yeaster Hi, I'm not sure if this... 11-24-2008, 03:06 AM
koda86 Thanks yeaster for your... 11-24-2008, 04:01 AM
yeaster I used this part ... 11-24-2008, 05:52 AM
VBA Noob Hi both, Please read... 11-24-2008, 09:05 AM
royUK Thread closed, OP ignored... 11-24-2008, 09:20 AM
  1. #1
    Forum Contributor
    Join Date
    11-22-2006
    Posts
    100

    Delete Rows After a filter

    Hello,


    I used to work a lot on VBA but now I forgot almost everything and I would need your help to restart again my work on VBA. I have a worksheet with data from Column A to AA and I have a filter on Row 1. I would like to select from this filter a certain value for column D and then delete the rows I dont need. So my code starts like this:
     Sheets("Export").Select
     Selection.AutoFilter Field:=4, Criteria1:="<>MY", Operator:=xlAnd
    But after that I would like to delete the rows that are matching the criteria <> MY. Do I need to select manually the rows and then after make Selection.delete or does it exist a code that can directly delete the rows that I have selected (<> MY) ?

    Thank you for your help !!!
    please Tell me if my description is not clear... so much time I have past since my last visit on this website !
    Last edited by VBA Noob; 11-24-2008 at 09:05 AM. Reason: Added Code Tags

  2. #2
    Registered User
    Join Date
    02-04-2008
    Posts
    17
    Hi,

    I'm not sure if this will help but this was the code I used delete the rows away after using auto filter. You could use it to adapt it to your own code.

        With ActiveSheet
                 If .AutoFilterMode = False Then Selection.AutoFilter
                        .Range("C4").AutoFilter Field:=1, Criteria1:="#N/A"
                        .Range("C4").CurrentRegion.Offset(1, 0).SpecialCells _
                (xlCellTypeVisible).EntireRow.Delete
                .AutoFilterMode = False
        End With
    Do let me know if this works.

  3. #3
    Forum Contributor
    Join Date
    11-22-2006
    Posts
    100
    Thanks yeaster for your response !! But I have some troubles in converting your code to my sheet: it must something like:

    Selection.AutoFilter Field:=4, Criteria1:="<>MY", Operator:=xlAnd
    .................(xlCellTypeVisible).EntireRow.Delete


    But between the two lines, I cannot find what to put before (xlCellTypeVisible).EntireRow.Delete.

    What did you try to do with your line (.Range("C4").CurrentRegion.Offset(1, 0).SpecialCells _) ? I am pretty sure I need to adapt this last one but I really dont know what this line does.

    Thanks

  4. #4
    Registered User
    Join Date
    02-04-2008
    Posts
    17
    I used this part
    .Range("C4").CurrentRegion.Offset(1, 0).SpecialCells
    to avoid deleting my header row, hence there's the
    offset(1,0)
    [which is the first row].

    Maybe if you still can't get it working right, you could post a sample spreadsheet for me and I can show you how to use it.
    Last edited by VBA Noob; 11-24-2008 at 09:03 AM. Reason: Added code tags

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi both,

    Please read forum rules below before posting again as you both need to use code tags next time

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Thread closed, OP ignored Infraction & requests to add Code Tags
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1