Home

Forcing input to uppercase

%3CLINGO-SUB%20id%3D%22lingo-sub-278761%22%20slang%3D%22en-US%22%3EForcing%20input%20to%20uppercase%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-278761%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20inserted%20the%20below%20code%20in%20the%20code%20window%20of%20Sheet1%20but%20nothing%20happens%20when%20I%20enter%20something%20in%20lowercase.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3EWith%20Target%3CBR%20%2F%3EIf%20Not%20.HasFormula%20Then%3CBR%20%2F%3EApplication.EnableEvents%20%3D%20False%3CBR%20%2F%3E.Value%20%3D%20UCase(.Value)%3CBR%20%2F%3EApplication.EnableEvents%20%3D%20True%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20help%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-278761%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-278811%22%20slang%3D%22en-US%22%3ERe%3A%20Forcing%20input%20to%20uppercase%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-278811%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Hans%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20worked%20just%20fine!%3C%2FP%3E%3CP%3EPlease%20make%20sure%20that%20the%20code%20is%20inserted%20in%20the%20worksheet%20code%20module%2C%20not%20in%20a%20separate%20module.%3C%2FP%3E%3CP%3ETo%20check%20that%20out%2C%20hover%20the%20move%20over%20the%20worksheet%20tab%2C%20right-click%2C%20and%20select%20%3CSTRONG%3EView%20Code.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EThen%20check%20if%20the%20code%20is%20inserted%20in%20there.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20so%2C%20it%20may%20be%20an%20error%20that%20prevents%20the%20event%20to%20be%20triggered%2C%20and%20to%20fix%20it%2C%20please%20update%20the%20code%20as%20follows%3A%3C%2FP%3E%3CPRE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20Resume%20Next%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20With%20Target%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20Not%20.HasFormula%20Then%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Application.EnableEvents%20%3D%20False%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.Value%20%3D%20UCase(.Value)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Application.EnableEvents%20%3D%20True%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20If%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20With%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20On%20Error%20GoTo%200%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3EEnd%20Sub%26nbsp%3B%20%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20that%2C%20save%20the%20workbook%2C%20and%20restart%20it%20to%20take%20effect.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20that%20helps%3C%2FP%3E%3C%2FLINGO-BODY%3E
Hans Knudsen
New Contributor

I have inserted the below code in the code window of Sheet1 but nothing happens when I enter something in lowercase.

 

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If Not .HasFormula Then
Application.EnableEvents = False
.Value = UCase(.Value)
Application.EnableEvents = True
End If
End With
End Sub

 

Can you help?

1 Reply
Highlighted

Hi Hans,

 

It worked just fine!

Please make sure that the code is inserted in the worksheet code module, not in a separate module.

To check that out, hover the move over the worksheet tab, right-click, and select View Code.

Then check if the code is inserted in there.

 

If so, it may be an error that prevents the event to be triggered, and to fix it, please update the code as follows:

Private Sub Worksheet_Change(ByVal Target As Range)
    
    On Error Resume Next
    
    With Target

    If Not .HasFormula Then
        Application.EnableEvents = False
        .Value = UCase(.Value)
        Application.EnableEvents = True
    End If

    End With
    
    On Error GoTo 0
    
End Sub 

 

After that, save the workbook, and restart it to take effect.

 

Hope that helps

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies