OK, see if this is what you want ... please don't test it on your live data ;-)
Sub sCheckPostCodes()
Dim lFR As Long ' First Row
Dim lLR As Long ' Last Row
Dim lLC As Long ' Loop Counter
Dim pcCell As Range
Dim AWF As WorksheetFunction
Set AWF = Application.WorksheetFunction
lFR = 2
lLR = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
' For each cell in the range ...
For lLC = lFR To lLR
' For convenience, set a range variable to the cell being checked
Set pcCell = Range("A" & lLC)
With pcCell
' Check if UK
If .Offset(0, 1) = "United Kingdom" Then
' get rid of all spaces
.Value = Trim(.Value)
.Value = AWF.Substitute(.Value, " ", "")
' Check length of field; London codes will be short
If Len(.Value) >= 5 Then
' Build the reformatted Post Code
.Value = Left(.Value, Len(.Value) - 3) & _
" " & _
Right(.Value, 3)
End If
End If
' Whatever is left, convert to Upper Case
.Value = UCase(.Value)
End With
Next 'lLC
Application.ScreenUpdating = True
End Sub
Regards
Bookmarks