Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default limit character length when copying or typing

I am creating a template with multiple columns that will be populated by
others. Some of these columns have specific character limitations--in these
cases I'd like to prevent them from going over the character limit. I've
considered using validation, but there is an excellent chance that some of
the columns will be populated by copying/pasting, in which case validation
doesn't help. I thought vba might be the best bet. What I'd love to have is
this:

If the person types or copies a value that exceeds the character limit, I
would like a general message to display saying something like, "You have
exceeded the character limit. Entries that exceed the limit will be
highlighted and truncated." Then I would like that to happen--that is, to
have their entry truncated to the max character limit, and that cell
highlighted. I would like to have this work whether they pasted in one cell
or multiple cells at a time. Does anyone have any ideas how I could
accomplish this? Any guidance would be appreciated.

Thanks,

Jeff
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default limit character length when copying or typing

Hi,

See if this gets you started. Checks for data entered into column A

HTH

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo wsexit
Application.EnableEvents = False
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Set rng = Target
For Each cell In rng
If Len(cell) 10 Then
MsgBox "You have exceeded the character length. Cell will be
truncated"
cell.Value = Left(cell.Value, 10)
Target.Interior.ColorIndex = 3
End If
Next
End If
wsexit:
Application.EnableEvents = True
End Sub

"goofy11" wrote:

I am creating a template with multiple columns that will be populated by
others. Some of these columns have specific character limitations--in these
cases I'd like to prevent them from going over the character limit. I've
considered using validation, but there is an excellent chance that some of
the columns will be populated by copying/pasting, in which case validation
doesn't help. I thought vba might be the best bet. What I'd love to have is
this:

If the person types or copies a value that exceeds the character limit, I
would like a general message to display saying something like, "You have
exceeded the character limit. Entries that exceed the limit will be
highlighted and truncated." Then I would like that to happen--that is, to
have their entry truncated to the max character limit, and that cell
highlighted. I would like to have this work whether they pasted in one cell
or multiple cells at a time. Does anyone have any ideas how I could
accomplish this? Any guidance would be appreciated.

Thanks,

Jeff

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default limit character length when copying or typing

Just a heads up,
Unless it was Toppers intent to color the entire target if any cell in the
target exceeded the length limitation, then the following line

Target.Interior.ColorIndex = 3

should be changed to
Cell.Interior.ColorIndex = 3

to color only the offending cells within the cells changed

But perhaps "Target" was his intent.

also, if the only restriction was to column A, you could use

set rng = Intersect(Target, Range("A:A"))
rather than
set rng = Target

No intention to criticize Topper's Excellent suggestion, just some
additional refinement suggestions.

--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Hi,

See if this gets you started. Checks for data entered into column A

HTH

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo wsexit
Application.EnableEvents = False
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Set rng = Target
For Each cell In rng
If Len(cell) 10 Then
MsgBox "You have exceeded the character length. Cell will be
truncated"
cell.Value = Left(cell.Value, 10)
Target.Interior.ColorIndex = 3
End If
Next
End If
wsexit:
Application.EnableEvents = True
End Sub

"goofy11" wrote:

I am creating a template with multiple columns that will be populated by
others. Some of these columns have specific character limitations--in

these
cases I'd like to prevent them from going over the character limit.

I've
considered using validation, but there is an excellent chance that some

of
the columns will be populated by copying/pasting, in which case

validation
doesn't help. I thought vba might be the best bet. What I'd love to

have is
this:

If the person types or copies a value that exceeds the character limit,

I
would like a general message to display saying something like, "You have
exceeded the character limit. Entries that exceed the limit will be
highlighted and truncated." Then I would like that to happen--that is,

to
have their entry truncated to the max character limit, and that cell
highlighted. I would like to have this work whether they pasted in one

cell
or multiple cells at a time. Does anyone have any ideas how I could
accomplish this? Any guidance would be appreciated.

Thanks,

Jeff



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default limit character length when copying or typing

Thanks Tom, it should be Cell not Target. Your comments are always welcome
.... that's how I learn!

"Tom Ogilvy" wrote:

Just a heads up,
Unless it was Toppers intent to color the entire target if any cell in the
target exceeded the length limitation, then the following line

Target.Interior.ColorIndex = 3

should be changed to
Cell.Interior.ColorIndex = 3

to color only the offending cells within the cells changed

But perhaps "Target" was his intent.

also, if the only restriction was to column A, you could use

set rng = Intersect(Target, Range("A:A"))
rather than
set rng = Target

No intention to criticize Topper's Excellent suggestion, just some
additional refinement suggestions.

--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Hi,

See if this gets you started. Checks for data entered into column A

HTH

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo wsexit
Application.EnableEvents = False
If Not Intersect(Target, Range("A:A")) Is Nothing Then
Set rng = Target
For Each cell In rng
If Len(cell) 10 Then
MsgBox "You have exceeded the character length. Cell will be
truncated"
cell.Value = Left(cell.Value, 10)
Target.Interior.ColorIndex = 3
End If
Next
End If
wsexit:
Application.EnableEvents = True
End Sub

"goofy11" wrote:

I am creating a template with multiple columns that will be populated by
others. Some of these columns have specific character limitations--in

these
cases I'd like to prevent them from going over the character limit.

I've
considered using validation, but there is an excellent chance that some

of
the columns will be populated by copying/pasting, in which case

validation
doesn't help. I thought vba might be the best bet. What I'd love to

have is
this:

If the person types or copies a value that exceeds the character limit,

I
would like a general message to display saying something like, "You have
exceeded the character limit. Entries that exceed the limit will be
highlighted and truncated." Then I would like that to happen--that is,

to
have their entry truncated to the max character limit, and that cell
highlighted. I would like to have this work whether they pasted in one

cell
or multiple cells at a time. Does anyone have any ideas how I could
accomplish this? Any guidance would be appreciated.

Thanks,

Jeff




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
SELECTING FROM A DROP DOWN LIST BY TYPING FIRST CHARACTER MARGARET KISS New Users to Excel 3 January 9th 08 08:53 PM
typing a complement (i.e. notA) character in Excel jheby Excel Discussion (Misc queries) 6 September 6th 06 12:30 AM
How do I limit the character length of a cell when typing Andy Excel Programming 1 July 27th 05 03:54 PM
Typing a quote character Vs pasting a quote character= what happens to the resulting CSV? Interesting!! Tom Ogilvy Excel Programming 0 August 3rd 03 02:53 AM
Typing a quote character Vs pasting a quote character= whathappens to the resulting CSV? Interesting!! Jon Peltier[_3_] Excel Programming 0 August 3rd 03 02:22 AM


All times are GMT +1. The time now is 01:32 PM.

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

About Us

"It's about Microsoft Excel"