Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Private Sub Workbook_SheetChange

Hello,
I expect to use the Private Sub Workbook_SheetChange event to prevent the
user from entering a text longer than 15 characters in a specific cell.

How can I do this?
Thanks for your help!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Private Sub Workbook_SheetChange

Hi,

Why don't you use dat validation instead

Select your cells then
Data|Validation
Select Text length
Select less than equal to
15

Mike

"Robert" wrote:

Hello,
I expect to use the Private Sub Workbook_SheetChange event to prevent the
user from entering a text longer than 15 characters in a specific cell.

How can I do this?
Thanks for your help!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Private Sub Workbook_SheetChange

Since you posted in programming................

You could set up event code to truncate anything over a certain number of
characters after user hits ENTER key

No message, no retyping.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" '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) 20 Then
.Value = Left(.Value, 20)
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 Fri, 17 Oct 2008 19:19:11 +0200, "Robert" wrote:

Hello,
I expect to use the Private Sub Workbook_SheetChange event to prevent the
user from entering a text longer than 15 characters in a specific cell.

How can I do this?
Thanks for your help!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Private Sub Workbook_SheetChange

Change 20's to 15

Gord

On Fri, 17 Oct 2008 11:32:51 -0700, Gord Dibben <gorddibbATshawDOTca wrote:

Since you posted in programming................

You could set up event code to truncate anything over a certain number of
characters after user hits ENTER key

No message, no retyping.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10" '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) 20 Then
.Value = Left(.Value, 20)
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 Fri, 17 Oct 2008 19:19:11 +0200, "Robert" wrote:

Hello,
I expect to use the Private Sub Workbook_SheetChange event to prevent the
user from entering a text longer than 15 characters in a specific cell.

How can I do this?
Thanks for your help!



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
Improve method of calling a private function in a private module XP Excel Programming 1 April 30th 08 06:41 PM
Workbook_SheetChange won't run XL Novice DD... Excel Programming 5 April 11th 08 12:19 AM
Workbook_SheetChange masterphilch Excel Programming 5 January 19th 06 08:35 PM
re : Possible to run private sub macros by writing another private ddiicc Excel Programming 5 August 26th 05 04:49 AM
Private Sub Running Other Private Sub Inadvertently Ross Culver Excel Programming 2 February 10th 05 07:17 PM


All times are GMT +1. The time now is 02:26 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"