Message Box: Cell Exceeds 1000 Characters

typewriterguy

New Member
Joined
Oct 29, 2008
Messages
24
Would someone be able to provide VBA guidance/correction for this, for Excel 2003?

I would like a message box to pop-up when a user enters > 1000 characters into any Excel cell. The message box should only have an ok button (no cancel or retry) and also include the custom text that is shown below.

"Your description in <FIELDNAME>exceeds Excel's character limit. Please either shorten your description or insert a new row."

I tried the below and was getting a run-time error. Thanks.

---
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("D10").Length > "1000" Then
MsgBox "Your description in <FIELDNAME>exceeds Excel's character limit. Please either shorten your description or insert a new row"
End If
End Sub
---
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You really don't need VBA for this, just use data validation,

Allow Text Length

data Less Than

Maximum 1000

then set the message alerts as you wish.
 
Upvote 0
Thanks the quick response. While what I'm looking for is a validation feature, I tried validation and found that each of the resulting message boxes provided an opportunity for the user to lose their entered data by clicking the cancel or retry buttons. I want a message box that only returns an Ok button and custom text.
 
Upvote 0
And so if the user tries to enter, say, 1005 characters, do you want the message to appear and then after they click OK, have the cell display

either

the first 1000 characters

or

the last 1000 characters

or

no characters (cell gets cleared)

or

some other text such as "typwriterguy rules"


Inquiring minds want to know.
 
Upvote 0
If the user enters a value that exceeds 1000 characters, say 1005, then I want the 1005 characters to be stored and for a message box (with ok button) to appear with the custom text and the user clicks ok. The user would decide whether to shorten the character length - not Excel.
 
Upvote 0
Well alright, but how will you enforce the non-action of a user to shorten the text after they click OK? Once that OK is clicked, they can move on to the next cell, or just enter even more text into D10 and click OK again, since that message box will have no teeth to it based on what you say you want.

Put this in your worksheet module, but please also note, I omitted (and of course you can reinstate it if you want) your message box text about Excel having a limit of 1000 characters per cell, that is factually not correct.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address <> "$D$10" Or .Cells.Count > 1 Then Exit Sub
If Len(.Value) > 1000 Then
MsgBox _
"Only 1000 characters are allowed in cell " & .Address(0, 0) & "." & vbCrLf & _
"You entered " & Len(.Value) & " characters." & vbCrLf & vbCrLf & _
"Please click OK and either shorten your description," & vbCrLf & _
"or insert a new row.", 48, "Character limit is exceeded."
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,454
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top