Back to Samples Menu

VBA Samples

Microsoft Excel

Force CAPS on Entry

Hate having to put your Caps Lock on or using the Shift key at all? Suppose you have a column in your Excel spreadsheet for two-letter US state entry, or you must enter T or F for True/False, or M or F for Male/Female. You keep missing it and typing it in lower case. Easy enough! This code changes any text entry in the designated range to upper case.

Place the following code on the ThisWorksheet code window. The Range ("C:C") can be changed to any range. C:C tells it to CAP any entry in the entire C column. You can change the range to anything you like, such as C1:C15.

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
If Not Application.Intersect(Target, Range("C:C")) Is Nothing Then
    Target(1).Value = UCase(Target(1).Value)
End If
Application.EnableEvents = True

End Sub