function help

Imran Azam

Board Regular
Joined
Mar 15, 2011
Messages
103
Hi Guys

i am struggling with a function I am trying to create , have some data as shown below on and excel sheet ( start from column A3)

Group nametotal Markaverage student markoverall
A
100​
80%​
High
B
80​
65%​
High
C
19​
14%​
Low
D
50​
60%​
None
E
10​
5%​
Low

i need to write a function which would allow me to input a group name and then return a message based on the rules below

  • If the inputted Group name doesn't exist in the data then return the message 'Group does not exist”
  • If the total mark of the inputted Group name is less than 20 but more than 10 OR the average student mark is less than 15% OR the overall is "low" then return the message " Group X is not ok" X being the name the group
  • If the total mark of the inputted planet is less than 60 but more than 20 AND average student mark is AT LEAST 60% AND overall is "None" then return the message " Group X is ok" X being the name the group
  • otherwise return message ' Group X is normal'
can anyone help me create this
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I have assumed that data you presented is on Sheet1, Here is afunctions to do what you asked. I hope I got the equations correct:
VBA Code:
Function groupcat(groupname As Variant) As String
With Worksheets("sheet1")
    lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
    inarr = .Range(.Cells(1, 1), .Cells(lastrow, 4))
End With
 notfnd = True
 For i = 3 To UBound(inarr, 1)
   If inarr(i, 1) = groupname Then
     notfnd = False
       groupcat = "Group " & groupname & " is normal"
      If (inarr(i, 2) < 20 And inarr(i, 2) > 10) Or inarr(i, 3) < 15 Or inarr(i, 4) = "Low" Then
       groupcat = "Group " & groupname & " is not ok"
      End If
      If (inarr(i, 2) < 60 And inarr(i, 2) > 20) And inarr(i, 3) > 60 And inarr(i, 4) = "None" Then
       groupcat = "Group " & groupname & " is ok"
      End If
      Exit For
   End If
 Next i
 If notfnd Then
       groupcat = "Group does not exist"
 End If
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

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