I use the following macro to format all cells in a column that should contain only zipcodes. If the cell is blank, contains a space, or contains a non-numeric character, the macro errors out and a message is given. Is there a way to modify this macro so that it will reposition the cursor in the cell that contained the error? There are sometimes thousands of rows in the spreadsheet, so it would be great if the macro could go right to the cell that has a problem.
Sub FormatZipcodes()
' Set up the error trap
On Error GoTo ErrHandle
For Each xCell In Selection
xCell.Value = CDec(xCell.Value)
Next xCell
Selection.NumberFormat = "General"
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Exit Sub
ErrHandle:
MsgBox Prompt:="An error occurred. Check zipcodes for hyphens, spaces, and alpha characters.", _
Title:="Formatting Error"
End
End Sub
Thanks for your help!
Cheryl