+ Reply to Thread
Results 1 to 6 of 6

Macro to delete Worksheets that don't contain a specific pattern

  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Macro to delete Worksheets that don't contain a specific pattern

    I am using the macro below to loop through multiple worksheets in my Excel workbook and delete ones that don't contain the inputted keyword.

    Is it possible to modify the code to use a pattern instead of a specific keyword (e.g. using Regex or Like Operator)? For example, looking to keep worksheets that contain SSNs (###-##-####). Once one SSN is found in a worksheet, code can move to the next worksheet.. Thanks.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,916

    Re: Macro to delete Worksheets that don't contain a specific pattern

    Hi is you use LookAt:=XlPart you will check on a cell containing the text, the moment it's true exit and continue to the next worksheet if false delete it and continue
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: Macro to delete Worksheets that don't contain a specific pattern

    Actually, it only deletes the worksheet if it does NOT contain the specified keyword..

    Regardless, still looking for a macro that searches by a regex-type pattern rather than keyword..Thx.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,916

    Re: Macro to delete Worksheets that don't contain a specific pattern

    Have you tried then looking for the number format in the cells

    Please Login or Register  to view this content.
    I have a cell with theis cusptom format (000)-000-0000 and thta's what the srting value shows, so look for number formats instead and not empty

  5. #5
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    263

    Re: Macro to delete Worksheets that don't contain a specific pattern

    Allright, will mark this as Solved. Came up with a different technique shown below...

    Please Login or Register  to view this content.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,916

    Re: Macro to delete Worksheets that don't contain a specific pattern

    Good one 👍

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to delete worksheets except one specific sheet
    By winmaxservices in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2015, 08:15 AM
  2. [SOLVED] Delete all blanks rows in specific range on all worksheets
    By Dumy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-01-2015, 03:06 PM
  3. VBA loop to insert and delete worksheets in a specific sheet within a list
    By supppy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2014, 09:02 PM
  4. [SOLVED] Delete specific row for all worksheets
    By lorena ferraz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2014, 10:44 AM
  5. How to delete entire row if first cell of it is empty for specific range and worksheets
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2014, 12:36 PM
  6. [SOLVED] Macro to delete all worksheets except for one with specific name
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 12:01 PM
  7. Auto delete row in this specific pattern
    By truongn2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2007, 11:20 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