Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sum a component of an array

Status
Not open for further replies.

jluft

Technical User
May 4, 2004
74
US
i will do my best to explain this

lets say i have the following table
as an example we can say it represents gdp over time

1 2 3
3 5 7
8 9 4
1 4 6
lets name this range("SampleRange")

lets say there are 3 years being evaluated (each with its own similar table) per 3 different countries (so we are looking at 9 tables in total)

the first array we create will be
PrimaryArray(Country,Year)
Each element of this array will be filled with the entire table range as depicted above
so as an example
PrimaryArray(Country1,2005) = range("samplerange")
To access 3 on the top row from this range, for example, we could enter
PrimaryArray(Country1,2005)(1,3)

My question is whether there is a way to attain the SUM of a particular entire column of data from this array without looping through the entire range

as an example, how could i use a line of code to produce the first column (3+7+4+6) = 20

thanks very much, and if further clarification is required i will try
 

jluft,

I'd make a SINGLE COMPOSITE TABLE...
[tt]
Country Year Val1 Val2 Val3
[/tt]
so if you want Val3 for Country1 and 2005...
[tt]
=sumproduct((Country="Country1")*(Year=2005)*(Val3))
[/tt]
where I have used Insert/Name/Create - Create names in TOP row to NAME the ranges.

Skip,

[glasses] [red]Be advised:[/red]To be safe on the FOURTH, don't take a FIFTH on the THIRD, or...
You might not come FORTH on the FIFTH! [bomb][tongue]
 
skip,
thanks for the response.
unfortunately i do not have this option as the data i am dealing with is much more robust than my example.

did you happent o see my 2nd posting? i presenteda simpler example..do you know if anything along these lines is possible or is it something that simply cannot be done within vba? thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top