+ Reply to Thread
Results 1 to 11 of 11

Array VBA Help

  1. #1
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Array VBA Help

    Howdy all!

    I'm trying to build a workbook that will read from a raw data table and consolidate into a second table.
    I've included a test page "Array VBA Help" and the actual workbook I'm trying to build (with a handful of sample entries) "Count Sheet Test (1)".

    Objectives:
    Have a macro that will
    1) Copy all of the static information from the raw data table (columns A and C in this example, more in my actual data), and paste them into the Export table, skipping blanks.
    2) Remove duplicates from the Export table
    ((I have code to do this first part, though it's not very elegant))
    Please Login or Register  to view this content.
    3) Calculate the total quantity of an item in a location and the total reserves of that item in that location
    ((I have very inefficient code for this part))
    Please Login or Register  to view this content.
    4) Find and display the maximum unit price of an item

    5) Calculate the aggregate value of the item across all locations at the maximum item value.

    I know parts 1 and 2 can be done very quickly (and probably better than I have).
    I'm pretty sure parts 3 and 5 are also easy code.
    Part 4, though is the beast that I don't have any concept of how to tackle.
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Array VBA Help

    After running Consolidate try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 04-28-2018 at 06:41 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Re: Array VBA Help

    Holy crap! I would give you 1,000 stars for this if I could.

    I don't know how this works, yet, but this works spectacularly!

    Thank you!

  4. #4
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Re: Array VBA Help

    One more thing, is it possible for the result in the aggregate column to be the total aggregate of a given item? I was using the following formula in column J, =I2*SUMIF(A:A,A2,G:G)

    So for example, item 1106-018 (in rows 27 and 28), it's the same item in two locations, with 1 unit in the first location and 3 units in the second. The unit price is $3,711.40, and the way the macro runs now it returns an aggregate of $3,711.40 for the first location and $11,134.21 for the second. However, I would like it to show an aggregate of $14,845.61 on each row.

    I know beggars can't be choosers, and I'm supremely grateful for what you've already written, so if this is a step too far, no worries.

    Thank you again!

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Array VBA Help

    You're welcome and thanks for the rep!

    The two fields you mention have different locations - as long as you want to keep the locations apart, I don't see any way around it - maybe if I could stroll again through the Bowdoin pines, I could think of something

    Edit: Would you want to group by Catalog & Warehouse - just by Catalog?
    Last edited by xladept; 04-30-2018 at 02:50 PM.

  6. #6
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Re: Array VBA Help

    So I asked this question over a year ago, and xladept gave me this brilliant bit of code

    Please Login or Register  to view this content.
    It works extraordinarily well; however, it was just recently brought to my attention that it is rounding off decimals to whole integers. I tried swapping out the CLng with CSng but then got errors in processing.

    I would appreciate it if someone could help me tweak the code so that it displayed decimal quantities.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Array VBA Help

    I just ran it again on my test sheet from last year and I get the pennies when I'm supposed to? Can you post another test sheet??

  8. #8
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Re: Array VBA Help

    New sheet uploaded.

    The sheet in question is Consolidated CAT, and the cells that are rounding are in G:H.
    Attached Files Attached Files

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Array VBA Help

    I get some pennies in those fields with this:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-31-2017
    Location
    Brunswick, ME
    MS-Off Ver
    2013 (work) and 365 (home)
    Posts
    70

    Re: Array VBA Help

    Success!

    Thank you once again!

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Array VBA Help

    You're welcome and thanks for the rep!

+ 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. Replies: 5
    Last Post: 02-22-2018, 01:47 AM
  2. Replies: 1
    Last Post: 01-04-2018, 01:07 PM
  3. [SOLVED] Array formulae with different sized array, e.g. array-if() or somproduct-if()?
    By hlhans in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-09-2016, 03:59 PM
  4. [SOLVED] Populate one array from another array and print new array as a range
    By Kaden265 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 07:52 AM
  5. [SOLVED] Quick Array question - Copy array to another array then resize?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-02-2013, 01:17 AM
  6. [SOLVED] Populate Listbox with all rows of a dynamic array where elements of a single array match.
    By Tayque_J_Holmes in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-07-2012, 04:54 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