Results 1 to 4 of 4

Remove all rows EXCEPT those with specific string in specific column

Threaded View

  1. #1
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    MS365 Version 2404
    Posts
    87

    Question Remove all rows EXCEPT those with specific string in specific column

    Hello all,

    As the title says, I'm trying to modify a macro that was originally used to remove all rows containing a set of strings in specific columns, to now remove all rows except those with a specific string in a specific column.

    I have the following, which doesn't give any error but does not seem to do anything:

    Sub RemoveAllExcept()
        Dim p, r As Range
        Application.ScreenUpdating = False
        p = "sup":
        With Sheets("sheet1") 'Applies to this Sheet Name
            If .FilterMode Then .ShowAllData
            Set r = .[f1:f2]
                    
            r(2).Formula = "=(a2<>" & p & " )" 'A2 i.e. this must be the column which contains the "except" text
            With .Cells(1).CurrentRegion
                .AdvancedFilter 1, r
                .Offset(1).EntireRow.Delete
            End With
            If .FilterMode Then .ShowAllData
            r.Clear
            .ListObjects(1).ShowAutoFilter = True
        End With
        Application.ScreenUpdating = True
        
        MsgBox ("Done")
    End Sub
    I have attached a sample workbook with the original sheet ("Sheet1"), and a results sheet, along with the macro. Simply click on the button to run the macro, though as I said earlier, it won't do anything other than show a message.

    Thanks for any help.
    Attached Files Attached Files
    Last edited by noname91; 09-05-2023 at 01:08 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2022, 02:12 PM
  2. Macro to remove rows that don't contain a specific string in column B
    By tisahardknocklife in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-16-2018, 08:21 PM
  3. Replies: 16
    Last Post: 04-10-2016, 07:51 AM
  4. Delete Rows with specific text in specific column
    By love2waltz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2015, 10:16 AM
  5. [SOLVED] Copy rows with specific text in specific column into specific sheet
    By Valemaar in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 08-22-2014, 03:23 PM
  6. Replies: 0
    Last Post: 10-23-2012, 04:59 PM
  7. Modify to Run On Specific Column and Remove trailing digits in string
    By pmterp in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-12-2012, 07:47 PM

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