+ Reply to Thread
Results 1 to 11 of 11

macro to sort and delete certain rows?

  1. #1
    Registered User
    Join Date
    05-02-2012
    Location
    bc
    MS-Off Ver
    Excel 2007
    Posts
    21

    macro to sort and delete certain rows?

    Hello,

    I'm fairly new to excel but have become pretty well versed in the basic functions.

    Have never done much with macros though.

    I've got a sheet of data for all orders placed throughout a month, who sold them, and what type they were (more data fields but these are all I'm really concerned with).

    I've been manually sorting the data, removing all types of sales that we don't need (Type 4) and then doing a "count if" to determine how many of each product was sold.

    Am going to be looking at a lot more data and am trying to build a macro that will sort the raw data, delete all the type 4 orders, then do the count if functions and set up charts etc. I'm pretty sure I can record the functions and charts but my concern is how do I get the macro to delete all of that type of order. Then, how do I account for different numbers of orders each month? Ie - if we have 600 orders next month instead of 500, how can I set the count if's etc to count until an empty cell rather than just count a set range. Thanks for any advice!

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: macro to sort and delete certain rows?

    Do you have a sample file that you can attach?

    To Attach a File:

    1. Scroll down to the window below your post Additional Options
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: macro to sort and delete certain rows?

    What column are you sorting by? What column is the type in? Does the type say just 4 or Type 4?

  4. #4
    Registered User
    Join Date
    05-02-2012
    Location
    bc
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: macro to sort and delete certain rows?

    to delete the 4's I've been just sorting them by type, highlighting all the 4's and deleting them manually. then using counta/countif to get some stats out of the data.

    they just say "4"

    thanks!

  5. #5
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: macro to sort and delete certain rows?

    Quote Originally Posted by gtiguy View Post
    to delete the 4's I've been just sorting them by type, highlighting all the 4's and deleting them manually. then using counta/countif to get some stats out of the data.

    they just say "4"

    thanks!
    That didn't address my first two questions. I need that for the code.

  6. #6
    Registered User
    Join Date
    05-02-2012
    Location
    bc
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: macro to sort and delete certain rows?

    I'm sorting by type only because I've been manually deleting them. Ideally I would like to find a way to take all the various salesperson numbers and have them split onto seperate tabs. Other than to delete the "4" type of work order I don't really need to sort have been just counting data. The "4" is type which is column b, order number is a and salesperson is d. Thanks, does that help?

  7. #7
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: macro to sort and delete certain rows?

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-02-2012
    Location
    bc
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: macro to sort and delete certain rows?

    Awesome, this worked perfectly, thanks for your help!

    One final piece, looking to split the resuts from one master sheet into individual tabs. Was sorting column e (employee id) and manually removing each group of rows into a new tab with the id as the tab name. Any ideas on if a macro can accomplish this?

    Also, any good books or online courses you would recommend? I'd like to learn more about editing this code so I don't have to bother the forum with every task I need to complete thanks

  9. #9
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: macro to sort and delete certain rows?

    This is untested, but you can use the same technique to do this

    Please Login or Register  to view this content.
    The best book is the book of experience (I can't believe I wrote that corny tripe!). Seriously, books can help, but it is just doing and practicing that hones the skills.

  10. #10
    Registered User
    Join Date
    05-02-2012
    Location
    bc
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: macro to sort and delete certain rows?

    Thanks again...

    Getting a few errors with this one that I'm not sure where to start troubleshooting.

    The first is "expected end sub". This goes away when I delete the public sub copydata line and replace with my own name for the macro.

    At "copybytype" I get a sub or function not defined compile error. Beyond that I get a syntax error as I start playing around.

    Any tips on where to start? Thanks again!

  11. #11
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: macro to sort and delete certain rows?

    none of those errors make any sense as far as I can see.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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