View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
AltaEgo AltaEgo is offline
external usenet poster
 
Posts: 245
Default limit number of characters in cell

You can do this with VBA.

Right-click the tab of the relevant sheet.
Click View Code
Paste the following:

A1:C9 in the code restricts it to a specific range. If you need this
restriction, amend to the appropriate values.

Private Sub Worksheet_Change(ByVal Target As Range)
Const rEval = "A1:C9"

Set isect = Application.Intersect(Range(rEval), Target)
If Not isect Is Nothing Then
If Len(Target.Value) 30 Then
Target.Value = Left(Target.Value, 30)
MsgBox ("Value must not exceed 30." & vbCrLf & _
"Entered data trimmed.")
End If

End If
End Sub

If you do not need the restriction, use this:

Private Sub Worksheet_Change(ByVal Target As Range)

If Len(Target.Value) 30 Then
Target.Value = Left(Target.Value, 30)
MsgBox ("Value must not exceed 30." & vbCrLf & _
"Entered data trimmed.")
End If

End Sub




--
Steve

"sue@solotel" wrote in message
...
Hi
Is there a way to limit the number of characters that can be entered into
a
cell ?
I am setting up a database for export to another programme that can only
take a descriptor line of 30 characters