title: Multiple if statements in a loop vba
body: <p>I am trying to run a simple if statement but can not get it to run for me without getting an error. Basically, I am trying to have multiple if statements within a loop, im guessing i have a minor error but cannot spot it, maybe with the else statements. Any help is appreciated </p>
  
  <pre><code>Sub ex13()
  
  Dim rgtimetable As Range, rgR As Range, counter As Integer
  Dim counter1 As Integer, counter2 As Integer, counter3 As Integer
  
  Set rgtimetable = Range("timetable")
  For Each rgR In rgtimetable
      rgR.Activate
      If classyear(ActiveCell.Value) = 0 Then counter = counter + 1   ' classyear is a function i am calling from above
  
      Else
      If classyear(ActiveCell.Value) = 1 Then counter = counter1 + 1
  
      Else
      If classyear(ActiveCell.Value) = 2 Then counter = counter2 + 1
  
      Else
      If classyear(ActiveCell.Value) = 3 Then counter = counter3 + 1
  
  Next rgR
  
  MsgBox counter
  MsgBox counter1
  MsgBox counter2
  MsgBox counter3
  
  End Sub
  </code></pre>