+ Reply to Thread
Results 1 to 4 of 4

Help debugging! select case does not recognize numbers from range 5 to 9

  1. #1
    Registered User
    Join Date
    05-27-2013
    Location
    Middle, Nowhere
    MS-Off Ver
    Excel 2003
    Posts
    13

    Help debugging! select case does not recognize numbers from range 5 to 9

    Hi, the macro I'm writing is supposed to generate a grade depending on the marks that have already been typed in. For example if a mark falls between 80 and 100, the grade given would be N [which stands for High distinction but that's irrelevant]. I have written the following code:


    Sub markToGrade()
    Dim mark As String
    Dim grade As String


    For i = 1 To 19

    mark = Cells(i, 1).Value
    grade = Cells(i, 2).Value


    Select Case mark


    Case 1 To 49
    Cells(i, 2) = "N"
    Case 50 To 59
    Cells(i, 2) = "P"
    Case 60 To 69
    Cells(i, 2) = "C"
    Case 70 To 79
    Cells(i, 2) = "D"
    Case 80 To 99
    Cells(i, 2) = "HD"

    Case Else
    Cells(i, 2) = "**"
    End Select

    Next i

    End Sub

    --
    The problem here is, the macro treats marks that fall in the range of 5 to 8 as "case else" and inputs HD if the mark is 9. What's happening? I'm defining mark as string because students with undetermined grades have ** as marks and integer doesn't recognize symbols. On a side note, is it possible to code i such that i = activecell?

    Many thanks in advance!

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,376

    Re: Help debugging! select case does not recognize numbers from range 5 to 9

    maybe something like
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: Help debugging! select case does not recognize numbers from range 5 to 9

    The problem is that you've defined mark as string and all your cases are for numbers.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    05-27-2013
    Location
    Middle, Nowhere
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Help debugging! select case does not recognize numbers from range 5 to 9

    thanks nilem! worked like a charm. I used string instead of integers because the marks column included symbols and numbers. Using integers will give me an error message whenever the macro bumps into any of the symbols

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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