+ Reply to Thread
Results 1 to 9 of 9

Can this Macro be cleaned up?

  1. #1
    Registered User
    Join Date
    12-09-2014
    Location
    Aurora, IL
    MS-Off Ver
    2016
    Posts
    33

    Can this Macro be cleaned up?

    I have a macro that deletes the sales information at the end of the month so I can create a new sheet for the next month.

    It works, and it works fine, it's just slow. I already turn off automatic calculation, and that helps to speed it up.

    I do have a large number of formulas with nested ifs and vlookups pulling information that i need to process the commissions, so that may be what is causing it, and there is no other easier way.

    At the very bottom of the data, i have the word "Finished" to signify the completion, since the number of total lines changes each month, and there is other necessary information below the totals that i don't want deleted. It's the only way I easily knew to make it stop.

    Please Login or Register  to view this content.
    It may be that nothing can be improved, and that's fine, but i thought I'd ask. I'm not exactly an expert in this arena.

    Thanks for the help.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Can this Macro be cleaned up?

    It's usually not a good idea to depend on activesheet or activecell since sometimes your idea of what's active and Excel's idea of what's active can be two different things. The issue you are having is doing things row-by-row. Whenever possible, work with entire ranges. This is what the attached code does, it goes down column C until it finds the word "Finished" and then deletes the entire range.
    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    12-09-2014
    Location
    Aurora, IL
    MS-Off Ver
    2016
    Posts
    33

    Re: Can this Macro be cleaned up?

    Sorry, the problem is, i have many sales people on the sheet, each with a header row and subtotal.

    I want to keep the header and subtotal, and only delete the sales information rows that change from month to month.

    However, you did tun me onto the idea of deleting all their sales information at once for a single salesperson. i had not thought about that.

    Now i just have to learn how to select all the rows from a set of data.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Can this Macro be cleaned up?

    Without seeing the spreadsheet, I can only speculate on how your data is laid out. But working with ranges rather than cells or rows or columns is generally faster.

    There are a couple of things to consider when looking for "boundaries" of your data. Helper Cells with MATCH() can really help out. Depending how you get your data, Excel Tables may also help. They automatically know what their boundaries are.

    If you can provide a sample spreadsheet without sensitive data, maybe there is something I can clue in on to help you identify the ranges.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can this Macro be cleaned up?

    Couldn't you use a template sheet?
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    12-09-2014
    Location
    Aurora, IL
    MS-Off Ver
    2016
    Posts
    33

    Re: Can this Macro be cleaned up?

    Norie -

    The sales people change so often, and there are so many other sheets that are tied to it, i wouldn't want to maintain a master as well as an ever-evolving monthly. in reality, i need some specialized commissions software. However, right now i'm leaps and bounds above where we were when i started. (1 sheet per person. manually entering all data). I'll get this company where it needs to go, but baby steps along the way.



    Here is the updated code, and it is infinitely faster. and by infinitely, i mean there is definitely a finite amount of time that has been eliminated from the process (i'd say about 8-10 min), but it seems infinite.

    Please Login or Register  to view this content.
    dflak, thank you for making me thing differently.
    Last edited by chriska416; 05-10-2016 at 06:23 PM.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Can this Macro be cleaned up?

    Glad to be of help

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Can this Macro be cleaned up?

    I wasn't suggesting a 'master' sheet but a template sheet which has no sales data in it and can be copied whenever needed.

    PS Your existing code would run quicker if you didn't use Select/Selection and, if possible, got rid of the looping.

  9. #9
    Registered User
    Join Date
    12-09-2014
    Location
    Aurora, IL
    MS-Off Ver
    2016
    Posts
    33

    Re: Can this Macro be cleaned up?

    How would i go about removing the select/selection parts? what other options are there?

+ 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. Replies: 2
    Last Post: 12-28-2015, 12:00 PM
  2. List of street addresses needs to be cleaned up into more columns
    By soli004 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2015, 01:18 PM
  3. Clunky formula needs to be cleaned up
    By suniljayanna in forum Excel General
    Replies: 0
    Last Post: 07-05-2012, 05:55 PM
  4. Can this code be cleaned up?
    By bhodge10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2011, 11:32 AM
  5. Data all over the sheet to be cleaned
    By quikgun15 in forum Excel General
    Replies: 3
    Last Post: 11-17-2010, 10:03 AM
  6. Array is not being cleaned up
    By apka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-30-2008, 11:20 AM
  7. Read value from combobox (cleaned off duplications)
    By sven_dau in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2006, 12:10 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