+ Reply to Thread
Results 1 to 2 of 2

Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria

  1. #1
    Registered User
    Join Date
    04-25-2016
    Location
    Norway
    MS-Off Ver
    2013
    Posts
    8

    Question Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria

    Hi all,

    i'm having a workbook with three sheets, "data", "arrays" and "graph". They look like so (note that this is just a selection, because my intention is to do this for more countries and categories) :
    In short, the concept is this:
    - calculate some sums based on the data sheet (very basics calculations)
    - create an empty table to be filled with the the calculated values and
    - create a graph based on the filled table (usually stacked columns graph, but that's a story for another time).

    Here are my questions so far:

    ====================================
    1) i want to create arrays using the arrays sheet. Most of them as you can see will hold text values. I've seen the Split solution, but that would render my arrays sheet pointless, plus the code would not be as flexible (and good-looking ) as i'd like. Ideally i'd like to add / remove entries in the arrays sheet (e.g. add a new country) and the code will recognize this change in the next run.

    Example:
    step1: find column with header "country_array" in the arrays sheet
    step2: fill county_array with the values in column, from the 2nd cell (excluding the header) to the last entry

    ====================================
    2) what is the VBA equivalent of SUMIFS function?

    For example, if i want the sales of cherries and strawberries for Norway in 2014, i would put =SUM(SUMIFS(E2:E8, A2:A8,{"cherries","strawberries"}, B2:B8,"Norway", C2:C8,2014))

    ====================================
    3) how do i replicate this until all entries (rows) are scanned in a column? In other words, what to do when the column (range) size is unknown (or dynamic).

    ====================================
    4) can i include this SUMIFS equivalent in a loop?

    Example:
    ' countries array size (to be used for the counter)
    countries_size = UBound(countries) - LBound(countries) + 1
    For c = 1 To countries_size
    SumNorway1 = SUM(SUMIFS(...B2:B8,countries(c)...)
    Next c

    ====================================
    5) as aforementioned, i'd like to create an empty table in the graph sheet, that will accept the calculated sums (as seen in graph sheet).

    Example:
    step1: as columns headers, put the elements of "years" array (if possible also merge the 2 cells for years as shown in the graph sheet)
    step2: as sub-columns (below the years), put the elements of "semester" array
    step3: as row headers, put the elements of "category" array

    ====================================
    6) and finally, how do i write a value (e.g. the sums calculated) to a cell according to multiple criteria?

    Example:
    FIND the cell with column = "2014" AND sub-column = "h1" AND row = "cherries", then copy the calculated SumNorway1 to that cell.

    -------
    PS: Consider me as a complete noob, who knows some programming in general and now getting serious with VBA

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Fill arrays from sheet / SUMIFS / create & fill table based on multiple criteria

    It would help a lot if you post a sample spreadsheet with non-sensitive data.

    Based on he description, I think it would help if you organized your data into Excel Tables. Excel tables know how many rows they contain, so they will help with dimensioning the array. Also the parts of a table are addressable by column heading name so you don't have to guess or compute what the range of data will be.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Skip x cells and fill (Fill/create weekly average from 7 days and fill down)
    By tunafishes in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-18-2016, 03:43 AM
  2. Using Data from 1 table to fill an empty one based on 2 criteria
    By moggal in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2016, 09:53 PM
  3. [SOLVED] find row based on multiple criteria and fill
    By pugulis in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-12-2016, 09:58 AM
  4. Fill Color in pivot table based on criteria in data
    By mihir_joshi01 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-11-2015, 04:44 AM
  5. [SOLVED] VBA fill in cells in a new column in table based on multiple criteria from other columns
    By HRA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2013, 06:48 AM
  6. [SOLVED] X Marks the Spot - Fill in table based on 2 criteria
    By Flyinace2000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-23-2012, 11:15 AM

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