excel vba help please

Imran Azam

Board Regular
Joined
Mar 15, 2011
Messages
103
Hi Guys

I have a task at work where i need to create a function based on the data below ( this is made up example data i)

i am struggling with this task and was wondering if anyone can help?

please note this is in sheet 1 from A4-d9

studentgradeaverage %status
James
55​
52​
pass
Ian
38​
35​
fail
Mike
80​
74​
high pass
Jane
65​
67​
pass
Will
10​
23​
none



The function needs to allow a user to type a student name via an input box and then do the following

  • If the typed student in the input box isn't in the student list then message should returns 'Student does not exist'
  • If the typed student name grade is between 16 and 40 OR the Average is 35 % OR the status is 'fail' then message should return 'undecided'
  • if the typed student name grade is between 5 and 15 and % is less or equal to 24% AND status is 'none' then message should return 'Student hasn’t progressed'
  • else message should return ' student has progressed'
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: excel vba function help
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: excel vba function help
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
hi how do i provide this link?
 
Upvote 0
You don't need to this time, as I have done it for you. But you need to do it yourself if you cross post in the future.
 
Upvote 0
Non-VBA solution posted in cross-post thread

c0259621=TESTsheet.xlsx
ABCDEFGHIJ
1
2Student NameGradeAverageResult
3student gradeaverage %statusJames5552Student has progressed
4James5552pass
5Ian3835fail
6Mike8074high pass
7Jane6567pass
8Will1023none
Sheet1
Cell Formulas
RangeFormula
H3H3=IFERROR(IF(G3="","",VLOOKUP(G3,A:B,2,FALSE)),"")
I3I3=IFERROR(VLOOKUP(G3,A:C,3,FALSE),"")
J3J3=IF(G3="","",IF(ISERROR(MATCH(G3,A:A,0)),"Student does not exist",IF(OR(AND(H3>=16,H3<=40),C4=35,D4="fail"),"Undecided",IF(AND(H3>=5,H3<=15,C4<=24,D4="none"),"Student hasn't progressed","Student has progressed"))))
 
Upvote 0
Non-VBA solution posted in cross-post thread

c0259621=TESTsheet.xlsx
ABCDEFGHIJ
1
2Student NameGradeAverageResult
3student gradeaverage %statusJames5552Student has progressed
4James5552pass
5Ian3835fail
6Mike8074high pass
7Jane6567pass
8Will1023none
Sheet1
Cell Formulas
RangeFormula
H3H3=IFERROR(IF(G3="","",VLOOKUP(G3,A:B,2,FALSE)),"")
I3I3=IFERROR(VLOOKUP(G3,A:C,3,FALSE),"")
J3J3=IF(G3="","",IF(ISERROR(MATCH(G3,A:A,0)),"Student does not exist",IF(OR(AND(H3>=16,H3<=40),C4=35,D4="fail"),"Undecided",IF(AND(H3>=5,H3<=15,C4<=24,D4="none"),"Student hasn't progressed","Student has progressed"))))
thanks for this but due to the requirements needs to be a vba soluation
 
Upvote 0
thanks for this but due to the requirements needs to be a vba soluation
This question is almost identical to the one you asked in a previous thread.
All you need to do is slightly modify the answer provided by @offthelip there
function help

Here is my modification of that code.

VBA Code:
Sub StudentStatus()


'    If the typed student in the input box isn't in the student list
'           then message should returns 'Student does not exist'
'    If the typed student name grade is between 16 and 40 OR the Average is 35 % OR the status is 'fail'
'           then message should return 'undecided'
'    if the typed student name grade is between 5 and 15 and % is less or equal to 24% AND status is 'none'
'           then message should return 'Student hasn’t progressed'
'    else message should return ' student has progressed'


    Dim inStudentName As String
    Dim msgStatus As String
    Dim lastrow As Long, i As Long
    Dim notfnd As Boolean
    Dim inarr As Variant
    
    inStudentName = InputBox("Enter student's name: ")
    If inStudentName = "" Then Exit Sub
    
    
    With Worksheets("sheet1")
        lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
        inarr = .Range(.Cells(4, 1), .Cells(lastrow, 4))
    End With
    notfnd = True
        For i = 1 To UBound(inarr, 1)
          If LCase(inarr(i, 1)) = inStudentName Then
            notfnd = False
              msgStatus = "Student " & inStudentName & " is normal"
            If (inarr(i, 2) < 40 And inarr(i, 2) > 16) Or inarr(i, 3) = 35 Or LCase(inarr(i, 4)) = "fail" Then
                msgStatus = "Student " & inStudentName & " undecided"
            ElseIf (inarr(i, 2) < 15 And inarr(i, 2) > 5) And inarr(i, 3) <= 24 And LCase(inarr(i, 4)) = "none" Then
                msgStatus = "Student " & inStudentName & " Student hasn’t progressed"
            Else
                msgStatus = "Student " & inStudentName & " Student has progressed"
            End If
            Exit For
          End If
        Next i
        If notfnd Then
              msgStatus = "Student does not exist"
        End If
        
        MsgBox msgStatus
End Sub
 
Upvote 0
Solution
This question is almost identical to the one you asked in a previous thread.
All you need to do is slightly modify the answer provided by @offthelip there
function help

Here is my modification of that code.

VBA Code:
Sub StudentStatus()


'    If the typed student in the input box isn't in the student list
'           then message should returns 'Student does not exist'
'    If the typed student name grade is between 16 and 40 OR the Average is 35 % OR the status is 'fail'
'           then message should return 'undecided'
'    if the typed student name grade is between 5 and 15 and % is less or equal to 24% AND status is 'none'
'           then message should return 'Student hasn’t progressed'
'    else message should return ' student has progressed'


    Dim inStudentName As String
    Dim msgStatus As String
    Dim lastrow As Long, i As Long
    Dim notfnd As Boolean
    Dim inarr As Variant
   
    inStudentName = InputBox("Enter student's name: ")
    If inStudentName = "" Then Exit Sub
   
   
    With Worksheets("sheet1")
        lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
        inarr = .Range(.Cells(4, 1), .Cells(lastrow, 4))
    End With
    notfnd = True
        For i = 1 To UBound(inarr, 1)
          If LCase(inarr(i, 1)) = inStudentName Then
            notfnd = False
              msgStatus = "Student " & inStudentName & " is normal"
            If (inarr(i, 2) < 40 And inarr(i, 2) > 16) Or inarr(i, 3) = 35 Or LCase(inarr(i, 4)) = "fail" Then
                msgStatus = "Student " & inStudentName & " undecided"
            ElseIf (inarr(i, 2) < 15 And inarr(i, 2) > 5) And inarr(i, 3) <= 24 And LCase(inarr(i, 4)) = "none" Then
                msgStatus = "Student " & inStudentName & " Student hasn’t progressed"
            Else
                msgStatus = "Student " & inStudentName & " Student has progressed"
            End If
            Exit For
          End If
        Next i
        If notfnd Then
              msgStatus = "Student does not exist"
        End If
       
        MsgBox msgStatus
End Sub
thank you so much
 
Upvote 0
A VBA solution has also been posted in the cross-post linked in post #4. An unfortunate duplication of effort.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,830
Members
449,096
Latest member
Erald

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