Sub ClearCells()
Dim cel As Range
For Each cel In Range("A:A")
If Len(cel.Text) > 12 Then cel.ClearContents
Next cel
End Sub
Sub ClearIfMoreThan12Characters()
Columns("A").Replace "?????????????*", "", xlPart, , , , False, False
End Sub
Try this code - the range is set to column A but you can amend that as needed.
VBA Code:Sub ClearCells() Dim cel As Range For Each cel In Range("A:A") If Len(cel.Text) > 12 Then cel.ClearContents Next cel End Sub
Thank youHere is another macro that you can try...
VBA Code:Sub ClearIfMoreThan12Characters() Columns("A").Replace "?????????????*", "", xlPart, , , , False, False End Sub
EDIT NOTE: You can replace Columns("A") with Selection since that is what you apparently asked for originally.
Sub aty()
With Intersect(ActiveSheet.UsedRange, Selection.EntireColumn)
.Value = Evaluate("if(len(" & .Address & ")<>12,""""," & .Address & ")")
End With
End Sub