I was trying to create a way to replace state abbreviations with full names. I found a great formula for this (below). What I would like is to replace the hard coded range with a prompt to the user for the range ("Select the List State Abbreviations"). I would also like the VBA script to ask the user where the state names should be placed ("Select First Cell for State Names").
Sub ReplaceStateAbbrev()
Const StateNames As String = _
"Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida," & _
"Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine," & _
"Maryland,Massachusetts,Michigan,Mississippi,Missouri,Minnesota,Montana,Nebraska," & _
"Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota," & _
"Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee," & _
"Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming"
Const StateIds As String = _
"AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MS,MO,MN,MT," & _
"NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY"
Dim vecStateNames As Variant
Dim vecStateIds As Variant
Dim cell As Range
vecStateIds = Split(StateIds, ",")
vecStateNames = Split(StateNames, ",")
***Add in Prompt to user for abbreviation range***
For Each cell In Range("R3:R50")
If cell.Value <> "" Then
***Add in Prompt to user for where to place full Names***
cell.Offset(0, 1).Value = Application.Index(vecStateNames, Application.Match(cell.Value, vecStateIds, 0))
End If
Next cell
End Sub
Sub ReplaceStateAbbrev()
Const StateNames As String = _
"Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,Florida," & _
"Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine," & _
"Maryland,Massachusetts,Michigan,Mississippi,Missouri,Minnesota,Montana,Nebraska," & _
"Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota," & _
"Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee," & _
"Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming"
Const StateIds As String = _
"AL,AK,AZ,AR,CA,CO,CT,DE,FL,GA,HI,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MS,MO,MN,MT," & _
"NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY"
Dim vecStateNames As Variant
Dim vecStateIds As Variant
Dim cell As Range
vecStateIds = Split(StateIds, ",")
vecStateNames = Split(StateNames, ",")
***Add in Prompt to user for abbreviation range***
For Each cell In Range("R3:R50")
If cell.Value <> "" Then
***Add in Prompt to user for where to place full Names***
cell.Offset(0, 1).Value = Application.Index(vecStateNames, Application.Match(cell.Value, vecStateIds, 0))
End If
Next cell
End Sub