Complex INDEX/MATCH or SUMIFS formula

Marta GH

New Member
Joined
Aug 9, 2017
Messages
4
Hello,

I have been struggling for a while with this one and decided to seek your help in solving my issue.

I have a 20 step questionnaire data that comes in the following format and it is downloaded into an excel spreadsheet in a table that looks like this (the table is called "test"):

Step 1Step 2Step 3Step 4Step 5
NYYNN/A

<colgroup><col style="text-align: center;"><col span="4" style="text-align: center;"></colgroup><tbody>
</tbody>

The only possible answers are "Y", "N" or "N/A" for each of the steps and there could be more than a hundred questionnaires completed (rows).

In a separate spreadsheet in the same file, I have a scorecard table that shows the values assigned to each of the 20 steps. It looks like this (the table is called "Scores"):

Step 1Step 2Step 3Step 4Step 5
213512

<colgroup><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"></colgroup><tbody>
</tbody>

I am trying to build a formula that will identify the heading of each question (Step 1-20), look up each heading among the columns on the scorecard table, locate the number assigned to it if the answer is either “Y” or “N” (ignore the “N/A”s) and add all those numbers for the base score.

Then, (can be split into to or more formulas), the formula will add only the “Y” answers and tabulate them against the base score for a final score.

For illustration purposes the formula would, for the tables above, produce the following: Add 2+1+3+5=11, then add 1+3, then divide 4/11 for a final score of 0.36 (or 36%)

I started by using an index/match combo but can't find a way to incorporate the condition for "Y" and "N": =INDEX(Scores!$A$3:$O$3,MATCH(Test!A2,Scores[#Headers],0))+INDEX(Scores!$A$3:$O$3,MATCH(Test!B2,Scores[#Headers],0))+INDEX(Scores!$A$3:$O$3,MATCH(Test!C2,Scores[#Headers],0))+INDEX(Scores!$A$3:$O$3,MATCH(Test!D2,Scores[#Headers],0))+INDEX(Scores!$A$3:$O$3,MATCH(Test!E2,Scores[#Headers],0))

About to toss the index/match because I think it is too complicated.. looking for a simpler solution. Really stuck with this one… any help is truly appreciated.

Thank you so much in advance for any help or guidance you can offer,

Marta
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Welcome on the forum!

Does you absolutely need to have this as an Excel formula or a VBA based formula could be correct?

A solution containing all what you need/want for 20 step could be pretty huge with an Excel formula.
 
Last edited:
Upvote 0
Thank you Roxxien for your response and warm welcome!!

I could totally go via VBA... I agree that the formula could be huge but then again, I would still need to build the formula into the macro regardless.

Any guidance would be very much appreciated!!

Marta
 
Upvote 0
I created an User Defined Function (UDF) for your problem.

The function have two parameter.
1. You put the range of your X step.
2. You put the range of your score. (need to put the same number of cell)

Code:
Function CorrectTest(ByVal Answer As Range, ByVal Score As Variant)
Dim cgood As Currency
Dim ctry As Currency
Dim i As Integer
Dim r As Range


'Loop through each answer
For Each r In Answer
    i = i + 1
    'If diffrent then N/A then add to "try" score
    If Answer(i) <> "N/A" Then
        ctry = ctry + Score(i)
        'If good answer then add to "good" score
        If Answer(i) = "Y" Then
            cgood = cgood + Score(i)
        End If
    End If
Next


'Calculte the final score
CorrectTest = cgood / ctry
End Function

Now, how to use an UDF, highly suggested to firstly try in a copy of the original workbook.
1. Open the VB editor in Excel with Alt+F11
2. Create a new module by right click on the left window then insert->Module
3. Paste the code above COMPLETELY
4. Close the VB editor
5. "Save as" your workbook in a format the enabled macro (.xlsm for example)
6. You now have a new Excel function in that workbook that you can use like any other natural function
 
Upvote 0
Holy cow... you are an absolute genius!!! Thank you SO MUCH!!!! Way beyond my wildest expectations.

THANK YOU!!!!!

Marta
 
Upvote 0
It have been my pleasure to help you with that.

It wasn't more complicated to have a variable number of cell then only for 20 cells.

Roxxien

If you have other problem, don't hesitate to come back on this forum.
 
Upvote 0
Or maybe this...


A
B
C
D
E
F
1
Step 1​
Step 2​
Step 3​
Step 4​
Step 5​
Result​
2
N​
Y​
Y​
N​
N/A​
36%​
3
Y​
Y​
N​
N/A​
Y​
83%​

Formula in F2 copied down
=SUMIF(A2:E2,"Y",Scores[[Step 1]:[Step 5]])/SUMIF(A2:E2,"<>N/A",Scores[[Step 1]:[Step 5]])

M.
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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