currently having an issue where if I feed state abbreviations into my code it spits out N/A if the abbreviation is already there but lower case IE wi instead of WI.
Is there any way to reverse check based on the code below?
Sub Convert_States()
Dim Ws As Worksheet
Const StateNames As String = _
"Alabama,Alaska,Alberta,Arizona,Arkansas,British Columbia,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Manitoba,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Brunswick,New Hampshire,New Jersey,New Mexico,New York,Newfoundland,North Carolina,North Dakota,Nova Scotia,Ohio,Oklahoma,Ontario,Oregon,Pennsylvania,Prince Edward Island,Quebec,Rhode Island,saskatchewan,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming"
Const StateIds As String = _
"AL,AK,AB,AZ,AR,BC,CA,CO,CT,DE,DC,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MB,MD,MA,MI,MN,MS,MO,MT,NE,NV,NB,NH,NJ,NM,NY,NF,NC,ND,NS,OH,OK,ON,OR,PA,PE,PQ,RI,SK,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY"
Dim StNames As Variant
Dim StIds As Variant
Dim c As Range
''''''LR Code is extraneous - Disabled for time being.
'Dim LR As Long
'LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
''''''
'dialogue box
Dim rng As Range
Set rng = Application.InputBox("Select State column", "Obtain Range Object", Type:=8)
'insert column to right
Columns(rng.Address).Offset(0, 1).Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Application.ScreenUpdating = False
StIds = Split(StateIds, ",")
StNames = Split(StateNames, ",")
For Each c In Range(rng.Address)
If c.Value <> "" Then
c.Offset(0, 1).Value = Application.Index(StIds, Application.Match(c.Value, StNames, 0))
End If
Next c
Columns.AutoFit
Range("B1").Select
Application.ScreenUpdating = True
End Sub
Edit - Clarification
My apologies was typing that out in the last 30 seconds before I left for the day. So what the code does already is search the row for full state name Colorado and spits out CO in the cell one row over. However some of the data received varies and will have Colorado in one cell, and a few cells down it will have CO, the CO gets output as a N/A as CO does not match up against what is being searched. So see below for kind of idea of what the incoming data appears as.
Input Code Outputs
WI N/A
Wisconsin WI
CA N/A
California CA
Iowa IA
MN N/A