[VBA] Fill arrays from sheet | SUMIFS | create & fill table based on multiple criteria

Dimitris254

Board Regular
Joined
Apr 25, 2016
Messages
139
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
:cool:) 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","<wbr>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(<wbr>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 :)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Couldn't you use a pivot table/graph?
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,038
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top