I have an input box where zip codes are entered, and in order for it to work with my code, I had to "Dim ZipCode as Long". The problem is there may be times when text is entered (for example, "South America" or "Europe") instead of a zip code. How can I change the code so that if someone enters text, it will look for text in column B rather than a number?
Code:
Sub GetData()
Dim ZipCode As Long
ZipCode = InputBox("Enter a zip code and click OK", "Zip Code Lookup")
With Worksheets("Field Data")
Temp = 0
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If ZipCode >= .Range("B" & i) And ZipCode <= .Range("C" & i) Then
MsgBox "Region: " & .Range("A" & i) & vbNewLine & "Contact: " & .Range("D" & i) _
& vbNewLine & "Email: " & .Range("E" & i), , "Zip Code Lookup"
Temp = 1
i = LastRow
End If
Next i
End With
If Temp = 0 Then
MsgBox "No data found matching that zip code", , "Zip Code Lookup"
End If
End Sub