MagnaForce
New Member
- Joined
- Jul 1, 2021
- Messages
- 21
- Office Version
- 365
- Platform
- Windows
Getting a mismatch error
VBA Code:
Sub City()
'This Sub is going to look at Column "C" which contains both County and City Names, if the cell
'contains a City name then it will move it to Column "B"
Dim Lastrow As Long, n As Long
Dim City As Variant
Lastrow = Cells.SpecialCells(xlCellTypeLastCell).Row
City = Array("Abingdon", "Alexandria", "Altavista", "Ashland", "Bedford", "Big Stone Gap", _
"Blacksburg", "Blackstone", "Bluefield", "Bridgewater", "Bristol", "Buena Vista", "Charlottesville", _
"Chase City", "Chesapeake", "Christiansburg", "Clifton Forge", "Colonial Heights", "Covington", _
"Culpeper", "Danville", "Elkton", "Emporia", "Fairfax", "Falls Church", "Farmville", "Franklin", _
"Fredericksburg", "Front Royal", "Galax", "Grottoes", "Hampton", "Harrisonburg", "Herndon", "Hopewell", _
"Lebanon", "Leesburg", "Lexington", "Luray", "Lynchburg", "Manassas", "Manassas Park", "Marion", _
"Martinsville", "Narrows", "Newport News", "Norfolk", "Norton", "Orange", "Pearisburg", "Petersburg", _
"Poquoson", "Portsmouth", "Pulaski", "Radford", "Richlands", "Richmond", "Roanoke", "Rocky Mount", "Salem", _
"Saltville", "Smithfield", "South Boston", "South Hill", "Staunton", "Suffolk", "Tazewell", "Vienna", _
"Vinton", "Virginia Beach", "Warrenton", "Waynesboro", "Williamsburg", "Winchester", "Wise", "Woodstock", "Wytheville")
For n = Lastrow To 1 Step -1 'finds the last row and works its way up
If Range("C" & n).Value = City Then '<getting a type mismatch on this line
Range("B" & n).Value = Range("C" & n).Value 'Copies the contents from column "C" to "B"
Range("C" & n).Value = "" 'Deletes contents in column "C" after it was copied
End If
Next
End Sub