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.
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
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.
 

machopicho

Well-known Member
Joined
Feb 28, 2010
Messages
606
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”)
 

fvdk

New Member
Joined
Aug 18, 2011
Messages
23
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.
 
Joined
Feb 8, 2002
Messages
893
Office Version
365
Platform
Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,439
Messages
5,486,900
Members
407,570
Latest member
cannotquitexcel

This Week's Hot Topics

Top