+ Reply to Thread
Results 1 to 9 of 9

macro to delete rows and sort

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    macro to delete rows and sort

    I have attached a worksheet to illustrate a "Before" (raw data) and "After" (desired results).

    Each row contains data on a forex trade. The variables which must be assessed in each row are:

    Currency Pair (e.g. GBP/USD).
    Opening Time
    Closing Time

    What I need to do is delete many rows in the raw data because they reflect a condition I do not want in my analysis, which is having multiple open trades of a single currency pair during the same time period.

    To perform my analysis I need to delete all trades (rows) which meet the above condition.

    The worksheet provides examples, along with a rudimentary tool I've used to help me sort/delete rows manually.

    Since I am looking at thousands of trades, a manual sort/delete is impractical. (my eyes don't like this kind of work!)

    The rudimentary tool I've used in manual sorts/deletes is simply to have a column which returns a "1" if a trade opens before an older trade has closed. I do this by first sorting the data by (a) currency pair then (b) date opened. Then I must manually go through multiple iterations of deleting trades until there all of the "1's" have disappeared.

    I'm hoping someone can show me a macro which might do this sorting/testing/deleting automatically, at least to the point where all I have to do is repeatedly press a "macro" button until there are no "1's"

    Thanks much for any help!
    Attached Files Attached Files
    Last edited by jrtaylor; 09-28-2009 at 05:08 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro to delete rows and sort

    In B15 and copy down,

    =SUMPRODUCT( (H$14:H14 = H15) * (J$14:J14 > I15))

    Rows with non-zero values should be deleted. You can decide if the > should be >=
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: macro to delete rows and sort

    shg, what an elegant solution! Thanks.

    Can you tell me how I incorporate this (or any formula) into a macro?

    JRT

  4. #4
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: macro to delete rows and sort

    OK, I start it off.... I found this code in another thread. Seems that if I can modify it it should do what I want: Find rows in column B which do not = 0, then delete the rows.

    Since I don't know VBA I've guessed at some of the variables (without success!!!):

    Can someone help? Thanks!


    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro to delete rows and sort

    The VBA is strightforward, but your example, with the excess narrative, is not likely in the actual layout.

    How about posting an actual example, sanitized as necessary?

  6. #6
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: macro to delete rows and sort

    Sanitized worksheet attached, with broken macro.

    Objective is to delete rows in column C which <>0, while retaining integrity of column W.

    Macro for which I need help:

    Please Login or Register  to view this content.


    Thanks!
    Attached Files Attached Files
    Last edited by jrtaylor; 09-27-2009 at 08:54 PM.

  7. #7
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: macro to delete rows and sort

    Can anyone assist with this macro? Thanks.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: macro to delete rows and sort

    Do Insert > Name > Define,

    rgnFormula refers to: =INDEX(TradeList!$C:$C, ROW(TradeList!$C$14) + 1):INDEX(TradeList!$C:$C, MATCH("zzz", TradeList!$D:$D))

    Then run this:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    666

    Re: macro to delete rows and sort

    Thanks shg! I appreciate your help.

+ 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