+ Reply to Thread
Results 1 to 9 of 9

Sort by Stock Name then list by Oppsite Transactions

  1. #1
    Registered User
    Join Date
    01-15-2011
    Location
    Kent, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Sort by Stock Name then list by Oppsite Transactions

    I need to create a macro which will sort data, first by Stock Name. Then, for each Stock Name, rows which are opposite transactions to be listed first. Opposite transactions are those which have the same stock name, same quantity but one is delivery and the other is receipt.

    So, in the attached spreadsheet, the data on the left should be sorted to show the data on the right.

    Can any please help me?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sort by Stock Name then list by Oppsite Transactions

    hi SMJE,

    Welcome to the Forum

    I'm (perhaps unnecessarily) concerned about mismatches...
    Does your real data have any date fields to help ensure that the correct stocks are being matched?
    Or is the stock name more of a "unique identifier" in your real data?
    Edit: or is your sample reflective of your actual data & there are no more fields that should match?

    Rob
    Last edited by broro183; 01-15-2011 at 08:45 PM.
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Sort by Stock Name then list by Oppsite Transactions

    Hi SMJE and welcome to the forum,

    Find the attached where there are 4 possible ways to deal with your data. I'm sorry but I like Pivot Tables.

    See the attached. I like the one with a NegDir column added to your data and an easy Pivot from it.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sort by Stock Name then list by Oppsite Transactions

    hi MarvinP,

    I like pt's too but in this case, I'm not sure if it's quite what the OP wants/needs. I maybe wrong but I think the OP wants to see all the detail & individual "matches" rather than a net result. I guess we shall see...

    Rob

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sort by Stock Name then list by Oppsite Transactions

    Hello SMJE,

    Welcome to the Forum!

    In my experience Shipping and Receiving operations use unique identifiers for tracking the stock like Purchase Order numbers or SKUs. The following macro is based on this assumption. A button has been added to "Sheet1" to run the macro. The results appear on "Sheet2". The attached workbook has both the macro and button added.

    Sort Stock Data Macro
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Registered User
    Join Date
    01-15-2011
    Location
    Kent, England
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Sort by Stock Name then list by Oppsite Transactions

    Quote Originally Posted by broro183 View Post
    hi SMJE,

    Welcome to the Forum

    I'm (perhaps unnecessarily) concerned about mismatches...
    Does your real data have any date fields to help ensure that the correct stocks are being matched?
    Or is the stock name more of a "unique identifier" in your real data?
    Edit: or is your sample reflective of your actual data & there are no more fields that should match?

    Rob
    Thanks all - The data is a daily report, so yes has a date field, but all will be identical.
    Yes the stock code is a unique identifier, there are other fields, but the fields which vary are: Stock code, direction, quantity.

    There is no need to worry about whether they are 'true matches' since we need matches to notify the broker who they need to deliver/receive to, and we only require that they have the same quantity.

    broro183 - I would prefer not to use a Pivot table.

    Leith Ross - thanks for the code - yes indeed it does bring opposite transactions to the top of the list, however the rows listed afterwards are not in the order I desire.

    I've attached a spreadsheet to show in more detail what I'm aiming for! TIA
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sort by Stock Name then list by Oppsite Transactions

    hi everyone,

    SMJE,
    There is no need to worry about whether they are 'true matches' since we need matches to notify the broker who they need to deliver/receive to, and we only require that they have the same quantity.
    Wow!
    I'm pleased the stock code is a unique identifier, but in my past (Warehouse related) job, I would have had my backside booted if I had matched movements on the basis of quantity. Mind you, it was food processing & did require a high level of tracability.

    Ignoring the "netting" effect caused by MarvinP's example pivot tables so far, why would you prefer not to use pivot tables?

    however the rows listed afterwards are not in the order I desire.
    I may be going a bit far here (edit: because you've said thanks & tia etc ), but, I think a "please" would fit into the above quite nicely

    Leith (or others),
    I'll be interested to see what you come up with. All I can think of is using a "Do Until" loop, but I haven't got any further than that!

    Rob
    Last edited by broro183; 01-18-2011 at 06:42 PM.

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Sort by Stock Name then list by Oppsite Transactions

    Hey Rob,
    When I first read this question I thought it was Stock Certificates or Stock Symbols he/she was dealing with, like MSFT or IBM. I've had a lot of practice, at tax time, trying to see why shares of stock don't add up. Pivot Tables have tamed these problems.

    Then Leith thought it was a SKU stock problem. Then the word "broker" was used. Then you used the term Warehouse, back to the idea of SKU's and what's in the store. I'm still a little clueless on what the real problem is.

  9. #9
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Sort by Stock Name then list by Oppsite Transactions

    lol!

    Good point MarvinP - at least you've taken your blinkers off to consider the other possibility of the problem relating to SKU's. If you hadn't posted, I wouldn't have even considered sharemarket style Stock Certificates etc & I would have just carried on, in ignorant bliss, thinking "that's odd to use the word 'Broker'".

    I guess we are all shaped by where we've been & what we've seen...
    BUT, I'll try & take my blinkers off.

    Well, hopefully the OP can give us the context - it may even influence our thoughts on the best solution.

    SMJE,
    Sorry, I haven't had a go at the coding for the latest requirements & am off to bed soon. I've got footy tomorrow, so it's unlikely to happen then but I'll try & put something together this weekend. Hopefully someone else can come up with a nice solution for you before then...

    Rob

+ 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