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

    Code
    1. For Each cell In Range("E2:E2634")
    2. Select Case cell.Value
    3. Case "UT", "MD", "NM", "VA"
    4. cell.Offset(0, 1).Val = "6"
    5. Case "PA", "NV", "CO", "CA", "NH"
    6. cell.Offset(0, 1).Value = "9"
    7. End Select
    8. Next cell
  • Jack in the UK

    Changed the title of the thread from “If/ElseIf Trouble” to “If ElseIf”.