Okay, I think you are asking for more than a simple cell validation can
handle; so I think you will need to use VB event code to do what you want.
Go to the worksheet you want this functionality on and right click its tab
(located at the bottom of the worksheet), select View Code from the popup
menu that appears, then Copy/Paste this code into the code window that
appeared when you did that...
'*************** START OF CODE ***************
Dim Contents As String
Const CellAddress As String = "B2:B5,E5"
Private Sub Worksheet_Change(ByVal Target As Range)
Dim X As Long
Dim C As Range
Dim IDs() As String
If Not Intersect(Target, Range(CellAddress)) Is Nothing Then
On Error GoTo Whoops
Application.EnableEvents = False
IDs = Split(Replace(Target.Value, ";", ","), ",")
For X = 0 To UBound(IDs)
If Len(IDs(X)) >= 15 Then
MsgBox "This Email ID..." & vbLf & vbLf & IDs(X) & _
vbLf & vbLf & "contains 150 or more characters. " & _
"That is too many characters and is not allowed", _
vbCritical, "Entry Too Long"
Target.Value = Contents
Exit For
End If
Next
End If
Whoops:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range(CellAddress)) Is Nothing Then
Contents = Target.Value
Else
Contents = ""
End If
End Sub
'*************** END OF CODE ***************
It was not clear to me from your postings whether there would be only one
cell ever that need this validation or whether there could be more than one;
so I set the code up to handle either situation. If you want only one cell,
set the CellAddress constant statement to that address; for example...
Const CellAddress As String = "E5"
Or, if you have more than one cell, use their addresses instead...
Const CellAddress As String = "E5,H7,J10"
Or, if you have a range of cells where the validation should apply, say
Column B, then use this instead...
Const CellAddress As String = "B2:B20"
or you can mix cells and ranges...
Const CellAddress As String = "E5,B2:B20,H7"
Now go back to the worksheet... any cell in the range you specify will be
checked for entries between semi-colons or commas being 150 characters or
more in length. If they meet that criteria, a message box will be displayed
advising of the 'error' and, after the MessageBox's OK button is pressed,
the cell will be returned to its former contents.
Rick