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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

VoG

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,079
Messages
5,509,143
Members
408,711
Latest member
EMexcel

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top