title: Assigning Grades using an Excel macro
body: <p>I have my results in <code>Column9</code> and I have to assign a grade for each student in <code>Column 10</code>.  This is my Excel macro code.</p>
  
  <pre><code>Sub grading()
  Dim k As Integer
  Dim result As String
  For k = 2 To 6
  If (Cells(k, 9) &gt;= 75) Then
     result = "A"
  
  ElseIf (Cells(k, 9) &gt;= 65) Then
    result = "B"
  
  ElseIf (Cells(k, 9) &gt;= 55) Then
     result = "C"
  
  Else
     result = "F"
  End If
  
  Cells(i, 10).Value = result
  Next k
  End Sub
  </code></pre>
  
  <p>But this gives a run-time error:</p>
  
  <blockquote>
    <p>Application defined or object- defined error.  </p>
  </blockquote>
  
  <p>What is wrong with this. This is my first macro so I would appreciate some help.</p>