View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Predefined Cell Character Length

You could use Data Validation and limit Text Length to how many characters
you wish.

Unfortunately this requires users to repeat their input until they get it
right.

Very annoying to me.

I would prefer event code which simply truncates any entries to a maximum
character count automatically.

Here is sample of what I mean.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A100" 'edit to suit
' "A1,A2,B1,C5,C6" for a non-contiguous range example
Dim cell As Range

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If Len(.Value) 10 Then
.Value = Left(.Value, 10)
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code"

Copy/paste into that module, Edit the range to suit. Alt + q to return to
the Excel window.


Gord Dibben MS Excel MVP

On Wed, 4 Mar 2009 16:49:01 -0800, Matt
wrote:

Hi,

I'm sure there is a way to do this but I am not to versed in excel. So I
have some data i'm pulling out a database to clean up but I want to make sure
users cannot enter more characters then i allow for a column/cell. i.e. Al
cells in clumn A can only be 10 characters at the most, Column be up to 30
etc.

It would be best for all excel versions but mostly will be used in excel 2003.

Thanks,
Matt