# Find a Value

Hi I have a cell that has three values in it, separated by comma (ex. 36, 36.5, 37)  I need to get the average of all three values then if cell d1 is = to "M" use  If <35, 15, if 35-37, 20, if 37-40, 25, if 40-45, 30, if 45-50, 35, else 45. if cell d1= "F" use  If <35, 11, if 35-37, 12, if 37-40, 13, if 40-45, 14, if 45-50, 15, else 20.
Incident ResponderAsked:
###### Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sr. Network EngineerCommented:
Hi Macone,

Your question is not very clear. Can you kindly elaborate what is that you are trying to achieve so that a formula according to the same can be created.

Regards,
Vipin
Incident ResponderAuthor Commented:
Sorry so on sheet 1, user will enter in cell d1 either "M" or "F" and in cell c1 the user enters three values separated by a commaa (example: 35, 36, 38).  If d1=M then take the average of the three values in c1 and obtain a score based on this criteria If <35, 15, if 35-37, 20, if 37-40, 25, if 40-45, 30, if 45-50, 35, else 45.  if d1=F then take the average of the three values in c1 and obtain a score based on this criteria  if cell d1= "F" use  If <35, 11, if 35-37, 12, if 37-40, 13, if 40-45, 14, if 45-50, 15, else 20.
Incident ResponderAuthor Commented:
Was my explanation clear
Older than dirtCommented:
Your ranges overlap. For example if D1 where "M" what score would 40 get, 25 or 30?
Incident ResponderAuthor Commented:
Sorry, If <35, 15, if 35-37, 20, if >37-40, 25, if >40-45, 30, if >45-50, 35, else 45.
Older than dirtCommented:
If a macro is acceptable then

``````Sub Score()
Dim strParts() As String
Dim curAvg As Currency
Dim intScore As Integer

If UCase(Range("D1")) = "M" Or UCase(Range("D1")) = "F" Then
strParts = Split(Range("C1"), ",")
curAvg = (Val(strParts(0)) + Val(strParts(1)) + Val(strParts(2))) / 3
Select Case curAvg
Case Is < 35
If UCase(Range("D1")) = "M" Then
intScore = 15
Else
intScore = 11
End If
Case 35 To 37
If UCase(Range("D1")) = "M" Then
intScore = 20
Else
intScore = 12
End If
Case 37.01 To 40
If UCase(Range("D1")) = "M" Then
intScore = 25
Else
intScore = 13
End If
Case 40.01 To 45
If UCase(Range("D1")) = "M" Then
intScore = 30
Else
intScore = 14
End If
Case 45.01 To 50
If UCase(Range("D1")) = "M" Then
intScore = 35
Else
intScore = 15
End If
Case Else
If UCase(Range("D1")) = "M" Then
intScore = 45
Else
intScore = 20
End If
End Select
MsgBox "Score is " & intScore
End If
End Sub
``````
Older than dirtCommented:
The above could be triggered automatically by a change in D1.
Incident ResponderAuthor Commented:
Thanks Martin, is there anyway to do this without a macro, the reason is I may have more than one cell to evaluate, it was be easier to copy an paste a formula down the rows.
Incident ResponderAuthor Commented:
To make it easier I made cell C1 just one value, instead of getting an average of 3 values.
Older than dirtCommented:
Still using 3 values I changed it into a user defined function that you can use just like a regular formula.

Usage:
=score(C1,D1)

``````Function Score(C As Variant, D As Variant)
Dim strParts() As String
Dim curAvg As Currency
Dim intScore As Integer

If UCase(D) = "M" Or UCase(D) = "F" Then
strParts = Split(C, ",")
curAvg = (Val(strParts(0)) + Val(strParts(1)) + Val(strParts(2))) / 3
Select Case curAvg
Case Is < 35
If UCase(D) = "M" Then
intScore = 15
Else
intScore = 11
End If
Case 35 To 37
If UCase(D) = "M" Then
intScore = 20
Else
intScore = 12
End If
Case 37.01 To 40
If UCase(D) = "M" Then
intScore = 25
Else
intScore = 13
End If
Case 40.01 To 45
If UCase(D) = "M" Then
intScore = 30
Else
intScore = 14
End If
Case 45.01 To 50
If UCase(D) = "M" Then
intScore = 35
Else
intScore = 15
End If
Case Else
If UCase(D) = "M" Then
intScore = 45
Else
intScore = 20
End If
End Select
Score = intScore
End If
End Function
``````

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Older than dirtCommented:
My apologies if you already know how to add this UDF but just in case...

In Excel, Press Alt+F11 to open Visual Basic Editor (VBE)

Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu

Copy the code (you can use the ‘Select All’ button if you like) and paste it into the right-hand pane of the VBA editor ("Module1" window)

Press Alt+F11 again to go back to Excel
Excel VBA DeveloperCommented:
You can do it without a macro, but a UDF is certainly a good solution.

For example, just to calculate the average value of the three, comma-separated numbers in cell C1 is:
=AVERAGE(VALUE(LEFT(C1,FIND(",",C1)-1)),VALUE(MID(C1,FIND(",",C1)+1,FIND(",",C1,FIND(",",C1)+1)-FIND(",",C1)-1)),VALUE(MID(C1,FIND(",",C1,FIND(",",C1)+1)+1,5)))

and that still doesn't include the functions necessary to select the respective M- or F-score.   If, for example, you had the result above in cell E1, then the score could be:

F1:  =INDEX(IF(D1="M",{15,20,25,30,35,45},{11,12,13,14,15,20}),MATCH(E1,{0,35,37,40,45,50},1))

See the attached example workbook.

-Glenn
EE-Q-28675601.xlsx
Incident ResponderAuthor Commented:
Martin,

Thank you for the help  I had a question on this part

strParts = Split(C, ",")
curAvg = (Val(strParts(0)) + Val(strParts(1)) + Val(strParts(2))) / 3

The average is now in cell "I", so I no longer need this part, to split it, so how do i modify this section to just use the value in I
Older than dirtCommented:
So you now have just one value in column C?
Incident ResponderAuthor Commented:
Martin,

Thanks I figured out how to change it for just one column.  I really appreciate the help on this issue.
Excel VBA DeveloperCommented:
How is the average being generated in column I?  Are you using the formula I suggested?  I am curious as to what formula or change you made to your application in order to get the average value now.

If so, you could use a modified version of my second formula to produce the score:

=INDEX(IF(D1="M",{15,20,25,30,35,45},{11,12,13,14,15,20}),MATCH(I1,{0,35,37,40,45,50},1))

You'd change D1 and I1 to the appropriate row.

-Glenn
Older than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.