+ Reply to Thread
Results 1 to 7 of 7

[SOLVED] Delete Subtotal if It Exists

  1. #1
    Registered User
    Join Date
    06-08-2016
    Location
    Seymour, Connecticut
    MS-Off Ver
    2013 MS Office
    Posts
    29

    [SOLVED] Delete Subtotal if It Exists

    Hi Guys-

    Hoping someone may be able to shed some light on this.

    I have a macro I've created but I want the macro to start by deleting the information and getting rid of the subtotals that we're there previously.

    The current code I have is this:

    Please Login or Register  to view this content.
    The problem is that if for some reason that subtotal isn't there, I get the error message:

    Run time error 424 Object Required. I want the macro to delete the subtotals if they are there but not do anything if they aren't. Any advice?
    Last edited by skellz022782; 07-11-2016 at 08:38 AM. Reason: Solved

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,522

    Re: Delete Subtotal if It Exists

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-08-2016
    Location
    Seymour, Connecticut
    MS-Off Ver
    2013 MS Office
    Posts
    29

    Re: Delete Subtotal if It Exists

    TMS Thank you for the reply.

    I'm no longer receiving the error message but the subtotals are still in place.

    When I used macro recorder initially do this I was given the following code:

    Please Login or Register  to view this content.
    My code is:

    Please Login or Register  to view this content.
    I do notice that when I run the macro recorder and I manually do it, an error message pops up after which requires me to hit okay.

    It says, "Microsoft excel cannot determine which row in your list or selection contains column labels, which are required for this command. I hit okay. And then I just click remove all on the subsequent subtotals window.

    Does that come into play when writing this?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,522

    Re: Delete Subtotal if It Exists

    Sounds like two problems to me. Not deleting them when they are there, and erroring out when they're not.

    Try Application.DisplayAlerts = False to address the first one.

  5. #5
    Registered User
    Join Date
    06-08-2016
    Location
    Seymour, Connecticut
    MS-Off Ver
    2013 MS Office
    Posts
    29

    Re: Delete Subtotal if It Exists

    Tried the below code and it works to get rid of all the data in columns A through J but still doesn't do anything with the subtotals unfortunately.

    Please Login or Register  to view this content.
    Also tried doing it like this:

    Please Login or Register  to view this content.
    Ended up with the same results in each case, deleted the data properly but didn't do anything with subtotals.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,522

    Re: Delete Subtotal if It Exists

    Suggest you post a sample workbook that demonstrates the problem(s). Ideally, I guess, one that has subtotals so that the first problem can be tested.

  7. #7
    Registered User
    Join Date
    06-08-2016
    Location
    Seymour, Connecticut
    MS-Off Ver
    2013 MS Office
    Posts
    29

    Re: Delete Subtotal if It Exists

    TMS-

    Thanks for reply. I have no idea why this worked but it did. I went to create a sample workbook to show the issue I was having and it ended up working. It seems the following code works:

    Please Login or Register  to view this content.
    May it has something to do with using cells. instead of a column range. In any case, I'll mark this thread solved.

+ 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. SUBTOTAL: Delete all rows associated with subtotal less than certain value
    By bikerchick1111 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2016, 12:20 PM
  2. Test if subtotal exists
    By jmicdk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-03-2016, 12:51 PM
  3. [SOLVED] Delete sheet if it exists
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-15-2015, 03:08 PM
  4. Im New...if subtotal exists then remove. if subtotal doesnt exist do nothing
    By ci89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2015, 04:53 PM
  5. Subtotal - Delete zero Subtotal and prior rows that calculate to that zero Subtotal
    By Whatsherface in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2012, 08:37 PM
  6. if a worksheet exists delete it
    By pavlos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2010, 03:15 AM
  7. Delete worksheet IF it exists
    By treva26 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2007, 10:01 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