+ Reply to Thread
Results 1 to 12 of 12

Sorting and deleting rows

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Danvers, MA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Sorting and deleting rows

    I have a code that auto-fills down for 200 rows, then deletes the unused rows and sorts them based on data in some of the cells, however when it sorts it does the entire worksheet and not row 6 and onwards as I had intended, also for selecting the rows to delete I had to copy and paste the same code over and over i was wondering if there is a simpler way to do this. Thank you for any assistance you can give me.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    Hello,

    Is it possible for you to include a copy of your workbook?

  3. #3
    Registered User
    Join Date
    07-06-2012
    Location
    Danvers, MA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Sorting and deleting rows

    this is a sample file ive been working with it should have all the information involved. basically select the first sheet and then run the macro.
    example.xlsm
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    Is the "CT1+CB-A1" will ever change?

    This is whats you are doing.
    1. You have a sheet "Formula" with some kind of sheet template that then you copy to a new sheet.
    2. You replace the constants with some data in the formulas to make reference to the sheets.
    3. you fill down your columns to the range.

    Couldn't just write the formulas in the code and then just put them the way they should be there?

    Thanks for the input

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    OK give this try and let me know if it works. I modified your code a little bit as well as your workbook to what I think is a better solution.

    In there workbook you will now find a hidden sheet with a dynamic range to cut down the several ORs you had in one of your columns. I also hid the Formula sheet because its not necessary for our task. We will leave it hidden there as reference as well


    Regarding your code:

    1. If want you need is data then you copy from a source but if you need a template just write it on the code.

    2. Autofill is a little tricky and can slow down big workbooks, it also make your screen flicker. Instead of that use an R1C1 formula and paste in every single cell you need them. My code might seem more complex than then one you had but in the end the outcome will be more efficient. Think of it as two steps (yours) :
    -Put a formula in A1
    -Autofill until A10
    One step (mine)
    -Put a relative formula in cells A1 to A10

    Note: Making an R1C1 formula is very easy just turn on the macro recorder, select the cell with the formula, hit enter, stop recording...and voila

    3. If you need to perform th same task several times or if your code starts getting too long think in modularization. In other words the breaking down of your code into smaller pieces that you will later assemble together. Look at my code to see what I mean. BTW in my code even though ther are more than one macro the only one you have to execute is WireDataMacro.

    I hope all this helps you out in your coding.

    Thanks

    Here is the File Example.xlsm

    And here is the code:

    Please Login or Register  to view this content.
    Thanks

  6. #6
    Registered User
    Join Date
    07-06-2012
    Location
    Danvers, MA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Sorting and deleting rows

    Yes CT1+CB-A1 change for every sheet i do this to. I thought about implementing the formulas directly into the code that would be more ideal but it give me errors because of the single quotes and the apostrophes. the formulas change because of the old sheet name always changing, i could update the numbers to be constant since im deleting rows that would normally be omitted buy this part of the formula but, they will still need to be different for every use of the macro.

    i tried the formula and it quite well except it lost the formatting for all numbers to have three decimal places and some rows didn't get deleted but i think with some small edits to your code it will work very well thank you.

    one problem i did find is that in the formulas within the code it has the old sheet name in it but if i use this macro on another sheet the formulas will call the wrong sheet. ill try to edit it and make it work.
    Last edited by Lotrking1010; 07-09-2012 at 09:00 AM. Reason: Formulas within code

  7. #7
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    Does the sample I gave you work?

  8. #8
    Registered User
    Join Date
    07-06-2012
    Location
    Danvers, MA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Sorting and deleting rows

    not exactly i need the old worksheet name to stay variable so that i can use it from other sheets, im going to try and impliment it into the part of your formula that has the equations so that i dont need the formulas sheet next.

  9. #9
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    Ohok sorry about that I will fix it. This afternoon I am at work now. Basically all you have to do is change the name of the sheet and use the reference sheet variable from the beginning of the code? I believe it's strOS

    So if the code says 'sheet1'! Change it to '" & strOS & "'!

  10. #10
    Registered User
    Join Date
    07-06-2012
    Location
    Danvers, MA
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Sorting and deleting rows

    ya I've tried that but like I've said something about the formulas breaks the code, I've turned what you had into this but it wont compile. thank you for all the help by the way it is greatly appreciated

    Please Login or Register  to view this content.
    Last edited by Lotrking1010; 07-09-2012 at 12:40 PM. Reason: spelling

  11. #11
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    I wish i could help you more right now p, but I am at work now.

    Try typing spaces in between

  12. #12
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Sorting and deleting rows

    Hi Lotrking1010 ,

    I am sorry for the delay. The issue is that we were using variable "strOS" that was defined in a different subroutine. So created a new variable in the new sheet to use it as the sheet name. I am sorry about that.

    So here is the code for the main Routine

    Please Login or Register  to view this content.
    Here you have the formula filler

    Please Login or Register  to view this content.
    And last but nor least the Filter. Which didn't change at all

    Please Login or Register  to view this content.
    If you have any questions please let me know.

    Example.xlsm

+ 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