How to limit the number of characters in a cell?
Hi,
data validation will reject the input but you can do it like this. Right
click your sheet tab, view code and paste this in. It works on column 1 (a)
change to suit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Target.Column < 1 Then Exit Sub
On Error GoTo getmeout
If Target.Characters.Count 30 Then
MsgBox "No more than 30 characters. text has been truncated"
Target.Value = Left(Target.Value, 30)
End If
getmeout:
End Sub
Mike
"filpass" wrote:
Dear Excel forum members,
I would like to limit the number of characters in a cell. How shall I do?
If a name is 50 characters long and I set up the limit at 30, will the 30
characters appear or will I receive an error message?
Thanks a lot for your help!
|