Search code examples
vbaexceltype-mismatch

VBA UCase Type Mismatch


Why on earth am I getting a type mismatch here? When I type "january" into the input box I am getting a type mismatch immediately after. Everything is a string(?).

Sub Test()

Dim sMonthOfMaintenance As String
Dim sMonthOfMaintenanceNumber As String

    sMonthOfMaintenance = InputBox("What month are you reviewing?")

    If UCase(sMonthOfMaintenance) = "JANUARY" Or "JAN" Then
        sMonthOfMaintenanceNumber = "01"
    End If

End Sub

Solution

  • After the OR statement, you must enter what you are trying to evaluate again. So it should read

    If UCase(sMonthOfMaintenance) = "JANUARY" Or UCase(sMonthOfMaintenance) = "JAN" Then