+ Reply to Thread
Results 1 to 8 of 8

Delete worksheets based on criteria

  1. #1
    Registered User
    Join Date
    06-28-2021
    Location
    Colorado, United States
    MS-Off Ver
    Office 365
    Posts
    5

    Delete worksheets based on criteria

    I have a workbook that has address information in it. One worksheet contains all data for all states, another worksheet contains summary data, and the other worksheets are for each individual state with the data copies from the worksheet that has all the data in it. I would like to delete any worksheet that does not have more than 200 records. I did try just adding worksheets that have more than 200 records rather than creating a delete subroutine, but I got farther with the delete. I do not want the worksheets containing all data ("vqueue") or the worksheet containing summary information ("Sheet1") to be deleted. I keep getting errors when I run the following code. Can anybody provide insight Thank you in advance!


    Please Login or Register  to view this content.
    Note that AF2 contains the number 200 as I could not seem to get it to work otherwise.

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Delete worksheets based on criteria

    I think you just need to nest the conditions together and use the rows count instead of a cell value.

    Please Login or Register  to view this content.
    Last edited by cubangt; 07-06-2021 at 05:53 PM.
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: Delete worksheets based on criteria

    Try on a copy of your WB first.
    Please Login or Register  to view this content.
    Last edited by jolivanes; 07-06-2021 at 11:22 PM. Reason: Spelling

  4. #4
    Registered User
    Join Date
    06-28-2021
    Location
    Colorado, United States
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete worksheets based on criteria

    When I run the code, I get a run-time error 438 - object doesn't support this property or method on the following line:
    Please Login or Register  to view this content.
    I'm not quite sure how to fix the error.

  5. #5
    Registered User
    Join Date
    06-28-2021
    Location
    Colorado, United States
    MS-Off Ver
    Office 365
    Posts
    5

    Re: Delete worksheets based on criteria

    Thanks for the reply! The code seems to run without triggering an error, but it doesn't actually delete any worksheets even though there should be at least 30 that should get deleted. Thoughts?

  6. #6
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Delete worksheets based on criteria

    Try this, i forgot to actually use the sheet name to check against.. if you notice i added the .Name to the sheet line

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Delete worksheets based on criteria

    This would also work

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,523

    Re: Delete worksheets based on criteria

    What is the result of the macro from Post #3?

+ 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. Compare 2 Worksheets based on single criteria and then delete row
    By jejnycta in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-17-2019, 05:12 PM
  2. [SOLVED] Split to Workbooks based on a Column followed by Worksheets based on another criteria
    By jaredli in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-26-2018, 03:27 AM
  3. [SOLVED] delete worksheets based on color
    By xi603 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-13-2017, 02:14 PM
  4. Delete rows based on the same value in different ranges of different worksheets
    By JamesTheRock in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2016, 05:38 AM
  5. Delete worksheets based on a list
    By khan_solo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2015, 07:05 PM
  6. [SOLVED] Delete Worksheets Based on Name from InputBox Criteria
    By d247 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-10-2014, 01:45 AM
  7. Delete Worksheets Based On Name
    By Fermented Reptile in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-18-2012, 11:02 AM

Tags for this Thread

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