+ Reply to Thread
Results 1 to 18 of 18

Need alternative excel can't keep a stock balance using sumifs is too slow.

  1. #1
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Need alternative excel can't keep a stock balance using sumifs is too slow.

    So in a spreadsheet, I have an excel table that lists qty going in and out for many different SKU's and running a sumif minus sumif for the balance takes too long so I need a way to vba code to a button to update.

    Jindon helped me with this while back that did this and also included a FIFO cost of goods part to it that was lightning fast but I no longer need the FIFO part and Just want it to run for the Inventory balance and I can't figure out how to seperate it out in the code it's too advanced for me to understand.

    Here is an example keep in mind this is a table in excel and actual data entries will be more than 20,000 rows and over 100 different SKU's and will also include more columns for details but this is enough to get an idea.

    SKU___________________QTY IN__________QTY OUT__________BALANCE
    PRODUCT A_______________5_________________________________5
    PRODUCT B_______________5_________________________________5
    PRODUCT C_______________5_________________________________5
    PRODUCT A________________________________4________________1
    PRODUCT B________________________________6________________-1
    PRODUCT A_______________10________________________________11

    I can't figure out how to attach an actual example file so I hope this is sufficient.
    Last edited by trickyricky; 12-05-2018 at 06:41 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Fast Code for running stock balance of inventory for many different sku's going in and

    title updated, thanks
    Last edited by protonLeah; 12-06-2018 at 03:44 PM.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100
    Quote Originally Posted by protonLeah View Post
    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 6)
    Am I able to receive responses now?

  4. #4
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100
    Anyone out there?

  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: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Hello trickyricky,

    Without seeing your code or your workbook, it takes more time to provide you with a solution. I created a workbook and macro based on the information you provided.

    The macro searches "Sheet1" for the headers: SKU, Qty In, Qty Out. The output is on "Sheet2" in columns "A:B" for the SKU and Balance. The output data is cleared each time the macro runs but not the headers.

    This should work quite fast since the inventory balance is placed in a dictionary object and output in an array to the worksheet. You may need to change the worksheet names to match the names in your workbook.

    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
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Oh, I understand I was just wondering, thanks for your reply. So your code gives me the balance in another sheet but what I'm actually looking for is the running balance per each line calculated in the BALANCE col.

    So staying in the same sheet, for the calculations in the BALANCE column is where I need the vba magic.

    My current approach is to take the sumif of [qty in] for the lines [sku], minus the sumif of [qty out] for the lines [sku] and those are expanding ranges as the list goes on.

    I will attach my example but keep in mind this is a small sample my list will actually get up to 20,000 or more rows with over 100 diff sku's.
    Attached Files Attached Files

  7. #7
    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: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Hello trickyricky,

    Thanks for the update. Is this workbook layout identical to the workbook you actually will be using the macro in?

  8. #8
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Basically although I will have other columns containing other details such as date, category, cost etc...

  9. #9
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    I can figure out the other columns later I just need the code for the Balance Column.

  10. #10
    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: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Hello TrickyRicky,

    The attached workbook is almost fully functional. There a few features I still need to add. Copy your data into Table1 and test it out. Feel free to move Table2 if you need to but it must stay on the same worksheet as Table1 (for now).
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Leith thanks for your time and effort but you are doing too much and its probably because I didn't explain it clearly. I just need vba to do the calculations for the balance column. I know it has to do with using scripting.dictionary and for loops I just dont how but I know its fast.

    Ive figured out a way to do it manually and that is to sort the data by sku then simply take the qty in - qty out + the previous rows balance. Then wrapping that in an if statement when the sku changes to start over but it seems to work pretty good.

    However i'd still like to see the vba method..

  12. #12
    Registered User
    Join Date
    06-21-2017
    Location
    Missouri, USA
    MS-Off Ver
    2007 through 2019
    Posts
    71

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Ricky this looks for values in column c starting at row 4and runs a sumif based on the listing name in column C for the qty in then again for the qty out. It subtracts the two then will output the answer in column F. It keeps going until it doesn't find an entry in column C.

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

  13. #13
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    SjMaxwell I gave your code a shot you're on the right track however it doesn't support for thousands of rows of raw data I am doing. I know it can be done, jindon did it in one of my other threads if anyone wants to disect what he did here: (this was for a table arranged differently with more columns and does FIFO cost of goods sold but i'm just trying to extract the inventory balance aspect of it)
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    06-21-2017
    Location
    Missouri, USA
    MS-Off Ver
    2007 through 2019
    Posts
    71

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    I was able to make it output only the inventory balance by deleting these three lines of code:
    Please Login or Register  to view this content.
    I'm sure without those lines the code is still doing a lot that it doesn't need to, but it's beyond my skill level. I am curious to see how this gets solved though!

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    trickyricky;
    re: your message

    What's wrong with your formula in Balance column?

  16. #16
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100
    Quote Originally Posted by jindon View Post
    trickyricky;
    re: your message

    What's wrong with your formula in Balance column?
    So the way I was doing that before you was too slow using the formula sumif of qtyin for the sku minus qtyout and expanding the ranges as it was copied down the column. Then the code you provided for doing the FIFO, you had it do the stocks balance as well, with fantastic speed and efficiancy.

    So now I don't need the FIFO part anymore I just want the code you wrote to do the stock's balance perpetually for each line down the list.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Need alternative excel can't keep a stock balance using sumifs is too slow.

    Is this how you wanted?
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    10-30-2010
    Location
    Kansas, USA
    MS-Off Ver
    Excel 2010
    Posts
    100
    Quote Originally Posted by jindon View Post
    Is this how you wanted?
    Please Login or Register  to view this content.
    jindon you got it! So I just want to know what makes this so fast and how do I learn this is there a youtube video on how you did that?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Stock/Inventory Control - Running Total
    By slntmnd in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-08-2018, 08:30 AM
  2. Replies: 4
    Last Post: 08-25-2017, 01:39 PM
  3. [SOLVED] Balance stock of inventory to be debited, while appearing the same code
    By DILIP-NAIR in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-25-2015, 10:52 AM
  4. Create Balance of stock for inventory control
    By m_costelloe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-29-2015, 12:32 PM
  5. VBA Code to pull Stock Balance Sheet Data from a Stock Symbol in a cell
    By akash1229 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 02-27-2015, 04:37 PM
  6. [SOLVED] Formula for Running Balance of stock levels
    By lindafinlay in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-21-2013, 12:09 AM
  7. Inventory Running Balance
    By walkinfaith in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-14-2008, 10:13 AM

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