If ElseIf

  • I have a set of data that has a column of State abbreviations in it. Each state abbreviation has a corresponding numerical value. I am trying to use looping If/ElseIf to determine the state abbreviation in one column, and based on the value, return the assigned numerical value to the empty cell next to it. With the code below, I get a run-time error 13 Type mismatch with the first IF line highlighted. I've spent most of the day searching for an answer, and the closest that I get is that I have an issue with the text vs. number value and I'm not sure how to solve it.

    I have include a sample workbook with the data that I'm referencing.

  • Try using a select case statement instead like

       For Each cell In Range("E2:E2634")
          Select Case cell.Value
             Case "UT", "MD", "NM", "VA"
                cell.Offset(0, 1).Val = "6"
             Case "PA", "NV", "CO", "CA", "NH"
                cell.Offset(0, 1).Value = "9"
          End Select
       Next cell

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!