Convert to Proper case with VBA

fvdk

New Member
Joined
Aug 18, 2011
Messages
23
Hi,

I've been busy with this for a couple of hours but can't seem to get it to work so thought I would ask it here hoping for a solution.

I have this form with a bunch of questions with mainly 'Yes' or 'No' answer so I'm using the list function for this in Excel. They can select 'Yes' or 'No' but they can also type it themselve. However when they type 'yes' or 'no' (lowercase) the data valiation will not accept it (as it needs to be proper case).

Is there any way with vba I can change the value automatically so when they enter 'yes' it is changed to 'Yes'?

I think you can do it with this function: Target.Value = STRCONV(Target.Value,VBPROPERCASE).

FIn my example cell E16 has a Yes or No answer and needs to be changed automatically to PROPER case if they enter lower or upper case.

Much appreciated if someone can help me.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "E16" Then
    Application.EnableEvents = False
    Target.Value = StrConv(Target.Value, vbProperCase)
    Application.EnableEvents = True
End If
End Sub

then try entering text in E16.
 
Upvote 0
VBA provides the UCase and LCase functions to convert text to upper and lower case, respectively. But what about proper case, you’ll need to use the StrConv function.
StrConv(”my text here”, vbProperCase)
will return
My Text Here
Alternatively, you can use the worksheet function PROPER, like this
Application.Proper(”more proper text”)
 
Upvote 0
Thanks, this seems to work. Meaning changing a 'yes' to a 'Yes. However this only works when I don't have the data validation using list on.

When I enter 'yes' with the data validation on (using list and then enter Yes;No) this does not work.

I tried using the data validation and then using the list function and then refer to a list with Yes or No and it works.

I guess there is no way to get it to work with data validation and then typing Yes;No?

Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "E16" Then
    Application.EnableEvents = False
    Target.Value = StrConv(Target.Value, vbProperCase)
    Application.EnableEvents = True
End If
End Sub

then try entering text in E16.
 
Upvote 0
Hello everyone. Sorry to resurrect an ancient thread. One of my good friends using Excel on a Mac says that this may not be working on the Mac platform here in 2019.

Rather than StrConv, I suggested to perhaps try this:
Target.Value = Application.WorksheetFunction.Proper(Target.Value)

I am just adding this in case someone in 2019 or later finds the thread.

Bill
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

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