title: Run-time error '1004' in a If else statement program
body: <p>I am trying to use two cells to determine which value to return back. The goal is to read in cell Z3 to determine which height to use, then cell AA3 to determine which Class to use based off the value the height provided. Once the class is found i would like it to print to cell AB3 then repeat for the next row and so on.</p>
  
  <p>I am currently getting a Run Time error 1004. I am not sure what is causing this I looked it up and said it could be cause by an empty variable but I am not seeing it. Any help would be great thanks!</p>
  
  <p>This is for a small project at work I am not great at VBA and just wanted to try and make a task easier and not take as long. </p>
  
  <pre><code>     Private Sub CRIC_CLASS_Click()
           Dim POLES As Worksheet
           Dim cell_value As String     ' Length
           Dim cell_value2 As String    ' MPCRIC
           Dim i As Integer             ' first intger for for loop
           Dim Class As String          ' Stores class value to return
           Dim Row As Integer   
           Set POLES = ActiveSheet
               For i = 3 To 500
               cell_value = POLES.Cells(i, "Z").Value
               cell_value2 = POLES.Cells(i, "AA").Value                       
                   If cell_value = 50 Then            
                       Row = 7                
                   ElseIf cell_value = 55 Then            
                       Row = 8            
                   ElseIf cell_value = 60 Then            
                       Row = 9            
                   ElseIf cell_value = 65 Then            
                       Row = 10            
                   ElseIf cell_value = 70 Then            
                       Row = 11            
                   ElseIf cell_value = 75 Then            
                       Row = 12            
                   ElseIf cell_value = 80 Then            
                       Row = 13            
                   ElseIf cell_value = 85 Then            
                       Row = 14            
                   ElseIf cell_value = 90 Then            
                       Row = 15            
                   ElseIf cell_value = 95 Then             
                       Row = 16            
                   ElseIf cell_value = 100 Then            
                       Row = 17            
                   End If            
  ' Check for height is 50            
              If Row = 7 And cell_value2 &lt;= 34 Then
                  Class = 4
              ElseIf cell_value2 &lt;= 36.5 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 39.3 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 42.1 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 44.6 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 47.4 Then
                  Class = H2
              Else: Class = NA
              End If            
  ' Check for height is 55            
              If Row = 8 And cell_value2 &lt;= 35.4 Then
                  Class = 4
              ElseIf cell_value2 &lt;= 37.8 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 40.7 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 43.5 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 46.4 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 48.8 Then
                  Class = H2
              Else: Class = NA
              End If            
  ' Check for height is 60            
              If Row = 9 And cell_value2 &lt;= 36.3 Then
                  Class = 4
              ElseIf cell_value2 &lt;= 39.2 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 42 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 44.9 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 47.7 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 50.6 Then
                  Class = H2
              Else: Class = NA
              End If                        
   ' Check for height is 65            
              If Row = 10 And cell_value2 &lt;= 37.7 Then
                  Class = 4
              ElseIf cell_value2 &lt;= 40.5 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 43.4 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 46.3 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 49.1 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 52 Then
                  Class = H2
              Else: Class = NA
              End If                       
  ' Check for height is 70            
              If Row = 11 And cell_value2 &lt;= 38.6 Then
                  Class = 4
              ElseIf cell_value2 &lt;= 41.9 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 44.8 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 47.6 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 50.5 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 53.3 Then
                  Class = H2
              Else: Class = NA
              End If            
  ' Check for height is 75            
              If Row = 12 And cell_value2 &lt;= 42.8 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 45.7 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 49 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 51.9 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 55.1 Then
                  Class = H2
              Else: Class = NA
              End If            
   ' Check for height is 80            
              If Row = 13 And cell_value2 &lt;= 43.7568 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 47.1 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 50.4 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 53.2 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 56.1 Then
                  Class = H2
              Else: Class = NA
              End If            
   ' Check for height is 85            
              If Row = 14 &amp; cell_value2 &lt;= 44.6772 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 47.9778 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 51.2785 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 54.5791 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 57.4462 Then
                  Class = H2
              Else: Class = NA
              End If            
   ' Check for height is 90            
              If Row = 15 And cell_value2 &lt;= 45.5952 Then
                  Class = 3
              ElseIf cell_value2 &lt;= 49.3333 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 52.2024 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 55.506 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 58.8095 Then
                  Class = H2
              Else: Class = NA
              End If            
    ' Check for height is 95            
              If Row = 16 And cell_value2 &lt;= 50.4157 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 53.2921 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 57.0449 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 60.3596 Then
                  Class = H2
              Else: Class = NA
              End If            
     ' Check for height is 100            
              If Row = 16 And cell_value2 &lt;= 51.4894 Then
                  Class = 2
              ElseIf cell_value2 &lt;= 54.8138 Then
                  Class = 1
              ElseIf cell_value2 &lt;= 58.1383 Then
                  Class = H1
              ElseIf cell_value2 &lt;= 61.4628 Then
                  Class = H2
              Else: Class = NA
              End If            
          Cells(i, "AB").Value = Class
  
          Next i
  
       End Sub
  </code></pre>