+ Reply to Thread
Results 1 to 2 of 2

Compile Error in VBA Code When Calculating Letter Grade

  1. #1
    Registered User
    Join Date
    03-13-2021
    Location
    Oakville
    MS-Off Ver
    16.46
    Posts
    4

    Compile Error in VBA Code When Calculating Letter Grade

    Hello,

    I am currently working on an assignment for school which has asked me to create a button that when clicked it determines a letter grade based off a percent in a cell. I have written what I think would do the trick but I keep getting error codes saying "compile error, expected end sub". I am new to programming and VBA so any help would be appreciated.

    This is what my code looks like right now

    Sub Button29_Click()
    Private Sub cmdGrade_Click()
    ' Calculation of grade based on percent in G17

    Dim sngPercent As Double

    sngPercent = Range("B3").Value


    If sngPercent >= 0.85 Then
    Range("H17") = "A"
    ElseIf sngPercent >= 0.7 Then
    Range("H17") = "B"
    ElseIf sngPercent >= 0.6 Then
    Range("H17") = "C"
    ElseIf sngPercent >= 0.5 Then
    Range("H17") = "D"
    Else
    Range("H17") = "F"
    End If

    End Sub

    Any feedback or help would be great, (I am not looking for someone to do the project for me just looking for guidance/assistance)

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Compile Error in VBA Code When Calculating Letter Grade


    Hi,

    your error comes from 2 consecutives Sub codelines so you must delete the useless one …

+ 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. [SOLVED] Compile error syntax error - spellnumber microsoft code
    By sunboy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-13-2022, 02:53 AM
  2. Replies: 5
    Last Post: 11-28-2019, 04:55 AM
  3. Macro To Change Letter Grade To Number Grade
    By florinel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2008, 11:14 PM
  4. [SOLVED] Grade Percentage into letter grade
    By James in forum Excel General
    Replies: 4
    Last Post: 12-13-2005, 11:30 PM
  5. [SOLVED] I am trying to set a letter grade for my students, HELP
    By ivano in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 09-06-2005, 07:05 PM
  6. I am trying to set a letter grade for my students, HELP
    By UTI Rod in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  7. [SOLVED] I am trying to set a letter grade for my students, HELP
    By UTI Rod in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM

Tags for this Thread

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