Hello!
I'm trying to create a macro that gives a message box and fills a cell red when a user enters over 15 characters in a cell. However, when I create the macro I notice that it only runs if you click back into the cell a second time. Is there any way to make the macro run upon exiting the cell the first time? My concern is that a user won't click back into the cell once they've already entered too many characters. Also, is there a way to make the red fill go away upon the user correcting the cell to 15 characters or less?
Thanks very much in advance!
I'm trying to create a macro that gives a message box and fills a cell red when a user enters over 15 characters in a cell. However, when I create the macro I notice that it only runs if you click back into the cell a second time. Is there any way to make the macro run upon exiting the cell the first time? My concern is that a user won't click back into the cell once they've already entered too many characters. Also, is there a way to make the red fill go away upon the user correcting the cell to 15 characters or less?
Thanks very much in advance!
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Len(Target) > 15 Then
MsgBox "Text is over 15 characters."
Range("A1").Interior.Color = RGB(255, 0, 0)
End If
End If
End Sub