How to always capitalize a letter

TSing3

Board Regular
Joined
Jan 7, 2015
Messages
54
I have a file in which employees have to enter a simple Y or N for Yes/No. How can I make this always be capitalized even if they key it in lower case?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Why not just use Data Validation on those cells, and limit them to choosing from the list of "Y" and "N" that you set up?

Another option would be to use VBA to automatically change all entries they make it certain cells capitalized.
 
Upvote 0
Didn’t even think of data validation. Duh! I’ll just do that.
The only caveat is if they were to use Copy/Paste to copy from another cell, it would overwrite the Data Validation.

If you wanted to go the VBA route, here is a robust code that will not only convert the lower case "y" and "n" to upper case, but also prevent anything else from being entered into these cells.
This code must be placed in the Sheet module that you want to apply it to (you can get there by going to the sheet, right-clicking on the sheet tab name at the bottom of the screen, selecting "View Code", and pasting this code in the VB Editor window that pops up).
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    
'   Apply this to column B
    Set rng = Intersect(Target, Columns("B:B"))
    
'   Exit sub if no updates in desired column
    If rng Is Nothing Then Exit Sub
    
    Application.EnableEvents = False
    
'   Loop through each cell
    For Each cell In rng
'       Skip line 1
        If cell.Row > 1 Then
'           Check to see if they entered "Y" or "N"
            If UCase(cell) = "Y" Or UCase(cell) = "N" Then
                cell = UCase(cell)
            Else
'               Check for any other entry
                If Len(cell) > 0 Then
                    cell.ClearContents
                    MsgBox "You entered an invalid entry", vbOKOnly, "TRY AGAIN!"
                End If
            End If
        End If
    Next cell
    
    Application.EnableEvents = True
    
End Sub
To change the range you wish to apply it to, just change the part below in red to the range you want to apply it to:
Rich (BB code):
    Set rng = Intersect(Target, Columns("B:B"))

Also note this line here, set to skip the first line (assumed header row):
VBA Code:
'       Skip line 1
        If cell.Row > 1 Then
If you have other rows at the top to skip that haven't been accounted for in the initial range declaration, just change the number after the greater than sign to reflect the last row number you want to exclude.
 
Upvote 0

Forum statistics

Threads
1,214,539
Messages
6,120,100
Members
448,944
Latest member
SarahSomethingExcel100

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