Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Code to set text length in cell

Hi Sandy,

An idea, barely tested. Add an ActiveX Textbox to your sheet, properties
BorderStyle = 1, maybe change the border colour, exit design mode. Don't
worry about position, size and visible. Select E22 and type some long text,
press Enter when done.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim s As String
s = TextBox1.Text
If Len(s) 5 Then
TextBox1.Text = Left(s, 10) ' change 10 to 20
ElseIf KeyCode = 13 And Shift = 0 Then
TextBox1.Visible = False
Me.Range("$D$22").Activate
Else
Me.Range("$E$22").Value = s
End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target(1).Address = "$E$22" Then
With Target(1).MergeArea
TextBox1.Left = .Left
TextBox1.Width = .Width
TextBox1.Height = .Height
TextBox1.Top = .Top
End With
TextBox1.Text = Target(1).Value
TextBox1.Visible = True
TextBox1.Activate
ElseIf TextBox1.Visible Then
TextBox1.Visible = False
End If
End Sub



Just a thought

Regards,
Peter T

"Sandy" wrote in message
...
I need to be able to control the text length in either a cell or in a

group
of merged cells (i.e. E22:G24, but merged).

Data Validation doesn't return an error message until you hit the enter
button. I would like something to return an error message if, for

example,
the maximum length is 20, then when the 21st character is hit, the message
box pops up.

Is this possible?
--
Sandy



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
cell text length conditional formatting - Excel 2003 Manc Shaun Excel Discussion (Misc queries) 3 March 26th 09 11:58 AM
Summing a column based on the length of text in a cell in anothercolumn [email protected] Excel Worksheet Functions 13 November 26th 08 05:42 PM
Zip Code Validation - length =5 or 9 Daron Excel Discussion (Misc queries) 11 November 5th 07 04:56 PM
How do I set up a text cell in Excel with restricted length? ElonRoger Excel Discussion (Misc queries) 2 September 28th 05 04:39 PM
The text length versus the cell size... shockley Excel Programming 2 September 14th 03 02:43 AM


All times are GMT +1. The time now is 11:28 AM.

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"