Home » excel » vb.net – Array based math within Excel formulas

# vb.net – Array based math within Excel formulas

Questions:

I’m working through an issue where I want to be able to total the number of correct selections a user has made. Each selection is weighted differently.

In excel I have a row of data points, each containing the correct answer, and below, each respondent’s data, such that their selection for the first question is in the same column as the key for the first question.

At the end of the row, I wish to include the number of points earned, so I would check across the row, if the respondents cell matches the provided cell, and if so, add in the appropriate number of points.

Unfortunately I cannot figure a way to do this using only a formula (no macros or custom functions as I am generating the excel files programically) and have resorted to a large string of “…+IF(C16=C8,1,0)+IF(D16=D8,5,0)+…”

Does anyone have any ideas?

Do you have the scores [weights] in the worksheet? If they are in row 9, for example try using `SUMPRODUCT` like this
`=SUMPRODUCT((C16:Z16=C\$8:Z\$8)+0,C\$9:Z\$9)`
`=SUMPRODUCT((C16:Z16=C\$8:Z\$8)+0,{1,5,2,3,4,5,6,7,1,2,3,4,5,6,1,2,3,4,2,3,4,4,7,1})`
`=SUMPRODUCT((C16:Z16=C\$8:Z\$8)*(C\$8:Z\$8<>""),C\$9:Z\$9)`