Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 516
Default Predefined Cell Character Length

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
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
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


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Predefined Cell Character Length

One more method.

In a helper column enter =LEFT(A1,10)

Copy down as far as you wish.

As users enter data in column A, the data will return only 10 chars in
column C

You can then copy column C and Paste SpecialValues over Column A


Gord

On Wed, 04 Mar 2009 17:12:36 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

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


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 516
Default Predefined Cell Character Length

Thanks for your help Gord I will try it out. probably the 2nd one, the 1st
one was too advanced for me.

it does sound like these options keep the character count to the number
specified but i was looking to a cut off but with no limit to anything under
10 characters. Meaning we may have an item that is 3 char, one that is 7 char
anoother that is 2 char so those would all be valid entries. They would only
be stopped from ever enter 11 char item #.

"Gord Dibben" wrote:

One more method.

In a helper column enter =LEFT(A1,10)

Copy down as far as you wish.

As users enter data in column A, the data will return only 10 chars in
column C

You can then copy column C and Paste SpecialValues over Column A


Gord

On Wed, 04 Mar 2009 17:12:36 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

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



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Predefined Cell Character Length

Matt

Whichever method you use..........event code or formula, will account for
cells with characters less than 10

=LEFT(A1,10) returns up to 10 characters.

If 3 chars in a cell just those 3 will be returned.

And what's advanced about installing the event code per my instructions?
Other than editing ranges<g

If you have more than one column to truncate to a different size, I can post
code for that.

If you use the formula method on another column that requires 20 chars, just
change the =LEFT(A1,10) to something suiting the column reference and number
of chars.

i.e. =LEFT(D1,20)


Gord


On Thu, 5 Mar 2009 12:02:01 -0800, Matt
wrote:

Thanks for your help Gord I will try it out. probably the 2nd one, the 1st
one was too advanced for me.

it does sound like these options keep the character count to the number
specified but i was looking to a cut off but with no limit to anything under
10 characters. Meaning we may have an item that is 3 char, one that is 7 char
anoother that is 2 char so those would all be valid entries. They would only
be stopped from ever enter 11 char item #.

"Gord Dibben" wrote:

One more method.

In a helper column enter =LEFT(A1,10)

Copy down as far as you wish.

As users enter data in column A, the data will return only 10 chars in
column C

You can then copy column C and Paste SpecialValues over Column A


Gord

On Wed, 04 Mar 2009 17:12:36 -0800, Gord Dibben <gorddibbATshawDOTca wrote:

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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Validation for Length & Character Type Rob Excel Discussion (Misc queries) 3 September 20th 07 01:11 PM
character length in data forms phdbd Excel Discussion (Misc queries) 0 October 11th 06 06:15 PM
assigning character length in a cell Audrey Excel Discussion (Misc queries) 4 July 30th 06 04:40 PM
Find character when the length varies Rookie_User Excel Discussion (Misc queries) 3 April 12th 06 07:17 PM
length of character data Saravanan Excel Discussion (Misc queries) 2 December 19th 04 06:49 PM


All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"