+'Add to your person XLSB
+'From there, you can add it to a toolbar
+ Dim ErrorText As String
+ Dim aStreetNo() As Variant
+ Dim iMaxRows As Integer
+ Set region = Range("A1").CurrentRegion
+ iMaxRows = region.Rows.Count()
+ iMaxCol = region.Columns.Count()
+ For iCol = 1 To iMaxCol
+ region.Cells(1, iCol).Value = Trim(region.Cells(1, iCol).Value)
+ 'On Error GoTo ErrHandler
+ ErrorText = "Could not find the StreetNo Column"
+ '=================================
+ Set region = CWS.Rows(1)
+ Set region = region.Find("StreetNo")
+ Set region = region.Next
+ ErrorText = "Give new row a name"
+ region.EntireColumn.Insert
+ Set region = region.Previous
+ region.Rows(1) = "ISODD"
+ ErrorText = "Odds and Evens"
+ '=================================
+ Set region = CWS.Rows(1)
+ Set region = region.Find("StreetNo")
+ Set region = region.Resize(region.Rows.Count, region.Columns.Count + 1)
+ For iRow = 2 To iMaxRows
+ oddValue = region.Cells(iRow, 1)
+ oddValue = (oddValue Mod 2)
+ region.Cells(iRow, 2) = oddValue
+ ErrorText = "Remove 'The' from envelope Name"
+ '=================================
+ Set region = CWS.Rows(1)
+ Set region = region.Find("EnvName")
+ Set region = region.Next
+ region.EntireColumn.Insert
+ Set region = region.Previous
+ region.Rows(1) = "Salutation"
+ Set region = CWS.Rows(1)
+ Set region = region.Find("EnvName")
+ Set region = region.Resize(region.Rows.Count, region.Columns.Count + 1)
+ For iRow = 2 To iMaxRows
+ sFixedName = region.Cells(iRow, 1)
+ If (LCase(Left(sFixedName, 4))) = "the " Then
+ sFixedName = (Mid(sFixedName, 5))
+ region.Cells(iRow, 2) = sFixedName
+ ErrorText = "Sort by Ward, Walk, Street, ISODD and then StreetNo"
+ '=================================
+ 'Ward, Walk, Street, ISODD and then StreetNo.
+ Set region = Range("A1").CurrentRegion
+ .SortFields.Add Key:=FindKey("Ward"), Order:=xlAscending
+ .SortFields.Add Key:=FindKey("Walk"), Order:=xlAscending
+ .SortFields.Add Key:=FindKey("Street"), Order:=xlAscending
+ .SortFields.Add Key:=FindKey("ISODD"), Order:=xlAscending
+ .SortFields.Add Key:=FindKey("StreetNo"), Order:=xlAscending
+ ErrorText = "Add Sequence Number"
+ '=================================
+ Set region = Range("A1").EntireColumn
+ Set region = Range("A1").EntireColumn
+ region.Cells(1, 1) = "Seq"
+ For iRow = 2 To iMaxRows
+ sFixedName = region.Cells(iRow, 1)
+ region.Cells(iRow, 1) = (iRow - 1)
+ ErrorText = "Delete Unneeded columns"
+ '=================================
+ RemoveColumn ("PollingDistrictCode")
+ RemoveColumn ("ElectorNumberWithSuffix")
+ RemoveColumn ("WalkManagerOrder")
+ RemoveColumn ("Building")
+ RemoveColumn ("StreetNo")
+ RemoveColumn ("Street")
+ RemoveColumn ("SubRoad")
+ RemoveColumn ("Locality")
+ RemoveColumn ("Westminster")
+ RemoveColumn ("County")
+ RemoveColumn ("CountyDivision")
+ RemoveColumn ("DevolvedRegion")
+ RemoveColumn ("DevolvedConstituency")
+ ErrorText = "Save file with correct ending"
+ '=================================
+ MsgBox saveFileForMerge()
+ ErrorText = "Close the file"
+ '=================================
+Function FindKey(sKeyName)
+ Set region = CWS.Rows(1)
+ Set region = region.Find(What:=sKeyName, LookIn:=xlValues, LookAt:=xlWhole)
+Sub RemoveColumn(sKeyName)
+ Set rg = FindKey(sKeyName)
+ Set rg = rg.EntireColumn
+Function saveFileForMerge()
+ Set WB = ActiveWorkbook
+ sFilename = WB.FullName
+ iPos = InStrRev(sFilename, ".")
+ sFilename = Left(sFilename, iPos)
+ sFilename = sFilename + "sdb"
+ WB.SaveAs Filename:=sFilename, FileFormat:=xlCSV
+ saveFileForMerge = sFilename