+ Reply to Thread
Results 1 to 10 of 10

excel vba function help

  1. #1
    Registered User
    Join Date
    11-28-2021
    Location
    london
    MS-Off Ver
    office
    Posts
    17

    excel vba function help

    Hi Guys

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

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

    student grade average 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'


    can anyone help with this please
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,724

    Re: excel vba function help

    This can be done quite easily with only formulas and no VBA. See attached solution.

    You said you are struggling but you have attached a file with no VBA. What progress have you made? Why do you require a VBA solution?
    Attached Files Attached Files
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-28-2021
    Location
    london
    MS-Off Ver
    office
    Posts
    17

    Re: excel vba function help

    Hi Jeff thank you for this , I have done vba on the original data but i am getting no where with this, they don't want formula as there is a lot of data, they want in interactive as in just type in the students name and get the result thanks

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,413

    Re: excel vba function help

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. As you are new here, I will do it for you this time: https://www.mrexcel.com/board/thread...lease.1188830/)

    Administrative Note:

    Members will tailor the solutions they offer to the version of Office (Excel) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your version is for Mac, please also state this. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,724

    Re: excel vba function help

    Quote Originally Posted by c0259621 View Post
    just type in the students name and get the result
    That is exactly what you get if you type a student's name into G3. I just extended it down several rows to show the results for all of your test data, plus a non-existent case, plus a blank case. You can just use one row if you want.

    If you want this in VBA instead you will have to be prescriptive about what you want this to look like to the user.

  6. #6
    Registered User
    Join Date
    11-28-2021
    Location
    london
    MS-Off Ver
    office
    Posts
    17

    Re: excel vba function help

    Quote Originally Posted by 6StringJazzer View Post
    That is exactly what you get if you type a student's name into G3. I just extended it down several rows to show the results for all of your test data, plus a non-existent case, plus a blank case. You can just use one row if you want.

    If you want this in VBA instead you will have to be prescriptive about what you want this to look like to the user.
    Thank you, when the function is run i need an input box to appear stating "type in students name and press ok" when that is done the the function runs based on the rules i stated before. thank you for your help

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,724

    Re: excel vba function help

    What makes the function run?

  8. #8
    Registered User
    Join Date
    11-28-2021
    Location
    london
    MS-Off Ver
    office
    Posts
    17

    Re: excel vba function help

    Quote Originally Posted by 6StringJazzer View Post
    What makes the function run?
    HI sorry for not stating this and being unclear ( i appreciate your help), a macro button is run that brings up the InputBox which always you to type the name of the students and then when you press ok this runs the function.

    sorry hope i am making sense

  9. #9
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: excel vba function help

    Assign this macro into a button:

    PHP Code: 
    Sub test()
    Dim Stud As String
    Stud 
    InputBox("Studen name:""Student status")
    Lr Cells(Rows.Count"A").End(xlUp).Row
    For 4 To Lr
        
    If Range("A4:A" Lr).Find(StudIs Nothing Then
        MsgBox 
    "Students does not exist"vbOKCancel
        
    Exit For
        Else
        If 
    Cells(i"A") = Stud Then
            
    If Cells(i"B") >= 16 And Cells(i"B") <= 40 Or Cells(i"C") = 35 Or Cells(i"D") = "fail" Then
            MsgBox 
    "undecided"vbOKCancel
            
    Exit For
            Else
                If 
    Cells(i"B") >= And Cells(i"B") <= 15 And Cells(i"C") <= 24 And Cells(i"D") = "none" Then
                MsgBox 
    "Student hasn't progressed"vbOKCancel
                
    Exit For
                Else
                
    MsgBox "Student has progressed"vbOKCancel
                
    Exit For
                
    End If
            
    End If
         
    End If
      
    End If
    Next
    End Sub 
    Attached Files Attached Files
    Quang PT

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,724

    Re: excel vba function help

    A VBA solution has also been posted at the cross-post linked by Ali, so there is duplicate effort. This illustrates why this rule exists (in both forums).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel function: countifs with nested OR function and wildcards
    By Franfv in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-18-2020, 03:57 AM
  2. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  3. Excel VBA Function Method API Windows Function User32.dll Alias Declare Library List . :)
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-17-2018, 07:51 PM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  6. Replies: 2
    Last Post: 03-30-2009, 04:04 AM
  7. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1