B
Brent
I have a cell that I want to display a message box for. The cell
should not contain more than 28 characters. If it does I want to
display a message box that tells the user how many characters they
entered and how many characters to remove from their entry. This is
my code.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cce17 As Double
If Not Application.Intersect(Target, Range("E17")) Is Nothing Then
cce17 = Len(E17)
If cce17 > 28 Then
MsgBox("You have entered a value in this field that is" &
cce17 & " characters in length. You will need to shorten your entry
by " & 28 - cce17 & "characters.", vbAbortRetryIgnore, "InvalidEntry
") As VbMsgBoxResult
End If
End If
End Sub
When I try to compile the code I get an error that says
Compile error:
Statement invalid outside Type block.
I know this is probably simple but I am a beginner to VBA and have
been unable to figure it out.
Thanks,
Brent Blevins
should not contain more than 28 characters. If it does I want to
display a message box that tells the user how many characters they
entered and how many characters to remove from their entry. This is
my code.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cce17 As Double
If Not Application.Intersect(Target, Range("E17")) Is Nothing Then
cce17 = Len(E17)
If cce17 > 28 Then
MsgBox("You have entered a value in this field that is" &
cce17 & " characters in length. You will need to shorten your entry
by " & 28 - cce17 & "characters.", vbAbortRetryIgnore, "InvalidEntry
") As VbMsgBoxResult
End If
End If
End Sub
When I try to compile the code I get an error that says
Compile error:
Statement invalid outside Type block.
I know this is probably simple but I am a beginner to VBA and have
been unable to figure it out.
Thanks,
Brent Blevins