VBA Coding to Repalce a List of Words with one word.
So I have a lot of state broken out into abbreviations like GA, FL, AL, and etc. What I am trying to do is write a code that with will replace them with "South". After looking at many threads I have put these lines together but still not getting the desired affect
Sub FindReplace()
Dim B As Long
For Each B In ActiveSheet.UsedRange
B = "GA" & "FL" & "AL"
B = Replace(a, "B", "South")
Next
End Sub
I keep on getting " For each control variable must be variant or object"
Trying Reference a cell and Input data in another column
What I am trying to do is get the references Abbrv in Column V and put the region in column W.
So for example: What is current happening is that the cells are just replacing the Abbriviations with the region and I know why its doing it.Column V |
Column V |
GA |
South |
IN |
Midwest |
What I want to happen is to have my coding identify the abbriviation in column V and input the South in column W. I need help with this.
Column V |
Column W |
GA |
South |
IN |
Midwest |
So Here is the coding I am working with:
Code:
Sub FindReplace()
Dim vAbbr As Variant, vStates As Variant, vNorthE As Variant, vMW As Variant, vWest As Variant
vStates = Array("GA", "FL", "AL", "TX", "NC", "SC", "LA", "KY", "AR", "OK", "VA", "TN", "MS", "DE", "DC", "WV")
vNorthE = Array("NJ", "PA", "NH", "CT", "ME", "MA", "NY")
vMW = Array("IN", "OH", "MD", "MI", "KS", "IL", "WI", "MO", "MN", "NE", "SD", "IA")
vWest = Array("CO", "AZ", "AK", "CA", "OR", "WA", "NV", "NM")
For Each vAbbr In vStates
Call ActiveSheet.Range("V:V").Replace(vAbbr, "South", vbTextCompare)
' Call ActiveSheet.UsedRange.Replace(vAbbr, "South", xlWhole, , , vbTextCompare) ' entire cell
Next vAbbr
For Each vAbbr In vNorthE
Call ActiveSheet.Range("V:V").Replace(vAbbr, "North East", vbTextCompare)
' Call ActiveSheet.UsedRange.Replace(vAbbr, "South", xlWhole, , , vbTextCompare) ' entire cell
Next vAbbr
For Each vAbbr In vMW
Call ActiveSheet.Range("V:V").Replace(vAbbr, "Midwest", vbTextCompare)
' Call ActiveSheet.UsedRange.Replace(vAbbr, "South", xlWhole, , , vbTextCompare) ' entire cell
Next vAbbr
For Each vAbbr In vWest
Call ActiveSheet.Range("V:V").Replace(vAbbr, "West", vbTextCompare)
' Call ActiveSheet.UsedRange.Replace(vAbbr, "South", xlWhole, , , vbTextCompare) ' entire cell
Next vAbbr
End Sub