+ Reply to Thread
Results 1 to 12 of 12

sorting data deleting common values

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    sorting data deleting common values

    Hey Guys,

    Having a little trouble creating a macro.

    Im trying to filter out rows with simular data in them

    I have four columns of data A,B,C,D
    I need a macro to run from 1 down to bottom of the spreadsheet

    Here is a snipet of the csv I bring in.
    1, 83.879, 8.224, -6.710,
    1, 83.879, 8.224, -6.710,
    1, 83.885, 8.223, -6.713,
    1, 83.845, 8.223, -6.713,
    1, 83.913, 8.235, -6.711,
    1, 83.933, 8.244, -6.711,
    1, 83.933, 8.244, -6.711,

    I need my macro to pick a row (starting at 1) then run through the rest of the rows searching for another row with data matching column "B" and "C" within matching values of +/- 0.050 (if it only matches b it shouldnt do anything it needs to match b and c), then deleting the row with the higher value in "D". The value in "D" could also be the same if thats true it should delete the one it finds and continue searching through the spreadsheet.
    Once its compared row 1 with the rest of the spreadsheet it can go onto row 2.

    Im not sure whats the fastest way to get the macro to run, if its picking one row and comparing to the rest of rows then moving to the next row or if you guys have any better ideas as unfortunatly I have approx 56,000 rows of data to sort thru.

  2. #2
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: sorting data deleting common values

    Start at Row 1,
    1. search matching column B & column B (with value +/- 0.050)
    2. if found(example at row 30), then compare column D value,
    ___a. if row 30 'D' greater than row 1'D' ---Delete row 30
    ___b. if row 30 'D' equal row 1'D' ---Delete row 30
    ___c. if row 30 'D' smaller than row 1'D' --- ignore row 30
    3. continuous loop, if found then go to step 2.
    4. loop finish then start with row 2.

    Is this what you want?
    -If the problem is solved, please mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved".

    -Always upload a workbook before start your question
    To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

    +++ If my answer(s) helped you, please add me reputation by click on * +++

  3. #3
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    You've written this much clearer than I,

    Just one change
    ___c. if row 30 'D' smaller than row 1'D' --- delete row 1 and proceed to row 2


    But that would be perfect~

  4. #4
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: sorting data deleting common values

    Please Login or Register  to view this content.
    Hi excel_joel ,
    it is better you give me more data, so i can find any error. For current situation, it work with the 7 samples. Only leave
    1 83.885 8.223 -6.713 is not delete.

  5. #5
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    Hey wenqq3,

    that looks great, its totally different to what I was working on this morning. Im running it now over the full 50,000 rows, and I can already see this will be another long macro.
    Its basically manually sorting thru all the data comparing the info, I just cant think of how I could speed this up ? or how to rewrite it ?

    Ill let you know how it goes

  6. #6
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: sorting data deleting common values

    So this macro is working?
    Speed up, add
    Please Login or Register  to view this content.
    after the Dim.... , will help.

  7. #7
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    Hey Wenqq3 I've sent you more data ! (pm)

    It seems to delete everything


    OMG screenupdating off !!! that is amazing !
    Last edited by excel_joel; 06-20-2013 at 10:15 PM.

  8. #8
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: sorting data deleting common values

    Book1.xlsx <-edit with attached sample
    I sort your row B, C, then D , ascending order.
    Put some logic check. if there is TRUE at column F, it must delete the row.
    So please do some sample that must deleted with you logic. So i can check the code correct or not.
    Thanks


    There is 2 OR in the code. Please change it to AND. Then the code should be fine :D
    Last edited by wenqq3; 06-21-2013 at 12:14 AM.

  9. #9
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    wabtesties.xlsxHey Wenqq3


    I've attached a bigger sample, I cant seem to upload a bigger one than this.

    I got a error in the code And I noticed it left a lot of repeats

  10. #10
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    =AND(B3>$B$2-0.05,B3<$B$2+0.05)

    You needed the $ in the fixed column

  11. #11
    Valued Forum Contributor wenqq3's Avatar
    Join Date
    04-01-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2003
    Posts
    868

    Re: sorting data deleting common values

    Dim aRow, bRow As Long
    change the Integer to Long.


    I noticed it left a lot of repeats
    Can you highlight for me after you run the macro at your attached sample file.

  12. #12
    Registered User
    Join Date
    11-15-2012
    Location
    australia
    MS-Off Ver
    Excel 2012
    Posts
    33

    Re: sorting data deleting common values

    Hey.
    I cant upload the file its just too big ? do you have an email I can send it to ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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