VBA InputBox Automatically Capitalize All Text When Typing

Ottsel

Board Regular
Joined
Jun 4, 2022
Messages
167
Office Version
  1. 365
Platform
  1. Windows
I have a case sensitive code that everyone tends to ignore and having to go back and fix everything to be in ALL CAPS can create a problem if left uncheck for a long period of time. Currently, I have 2 input boxes that appear requiring input, which a simple press of the 'caps lock' would work, but seems that's not simple enough.

Is there a way to have it, so when the input boxes appear that when users begin typing it will automatically have everything be capitalized?
'
'
'
Application.DisplayAlerts = False
Builder = InputBox("Please input the Builder Code.", "ABC Corp.")
ActiveWorkbook.Sheets.Add
Tract = InputBox("Next, input the Tract Code.", "ABC Corp.")
'Avoid error popup
If WorksheetExists(Tract) Then
MsgBox Tract & " already exists -" & vbCrLf & "Redirecting you there now.", _
vbInformation, "ABC Corp."
ActiveSheet.Delete
Sheets(Tract).Select
Application.DisplayAlerts = True
Exit Sub
Else
ActiveSheet.Name = Tract
End If

Currently, this is my InputBox Code selection. I removed the message boxes reminding to make everything capitalized, since its ignored already.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You can't show the user capitalized text in an input box as they type, but you can convert it after they type it:

Rich (BB code):
Tract = UCase(InputBox("Next, input the Tract Code.", "ABC Corp."))


If you really, really want to show it capitalized as they type you have use a custom UserForm instead of InputBox.
 
Upvote 0
Solution
That'll work. Didn't think of that. Thank you!
 
Upvote 0
You can't show the user capitalized text in an input box as they type, but you can convert it after they type it:

Rich (BB code):
Tract = UCase(InputBox("Next, input the Tract Code.", "ABC Corp."))

If you really, really want to show it capitalized as they type you have use a custom UserForm instead of InputBox.
I appreciate that this has been solved, but I saw the thread title and was curious to see what was being discussed. 6StringJazzer is absolutely right - the InputBox doesn't allow you to input only capital letters, and you would normally have to fashion some kind of Userform to accomplish that task... or so we all thought until it was demonstrated on this forum that, in fact, it can be done! It takes a whole lot of complicated code, though.


To be clear, I'm not suggesting that you should try it or anything, I just thought you both might be interested, is all :)
 
Upvote 0
it was demonstrated on this forum that, in fact, it can be done! It takes a whole lot of complicated code, though.
Yikes! Yeah, I guess it would work, but holy crap, that's a lot of code for something you could do in a few lines in a UserForm.

I whipped this up in less than 10 minutes.
 
Upvote 0
Well, to be fair, it's doing more than just enforcing capital letters in an inputbox, but I agree re: UserForms. Entirely underrated. There is also the added benefit that they can be displayed modelessly too!
 
Upvote 0
Oh, and I liked your approach with the Userform. Making it callable like the InputBox function was a very nice touch.
 
Upvote 0
Thanks! It's also possible to prevent a direct call to Show and only allow the function to be called, but I didn't get into all that.
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

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