Convert to Proper case with VBA
Results 1 to 5 of 5

Thread: Convert to Proper case with VBA
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2011
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Convert to Proper case with VBA

    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.

  2. #2
    Legend VoG's Avatar
    Join Date
    Jun 2002
    Location
    127.0.0.1
    Posts
    63,651
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    8 Thread(s)

    Default Re: Convert to Proper case with VBA

    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.
    HTH, Peter
    Please test any code on a copy of your workbook.

  3. #3
    Board Regular machopicho's Avatar
    Join Date
    Feb 2010
    Location
    Varese (Italy) Village: Lat. 45° 43' 48.36" N Long. 8° 48' 9.72" E
    Posts
    606
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Convert to Proper case with VBA

    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”)
    Regards
    Machopicho

    ---> All'apprendimento non si dedica MAI troppo tempo!!! <---

  4. #4
    New Member
    Join Date
    Aug 2011
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Convert to Proper case with VBA

    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?

    Quote Originally Posted by VoG View Post
    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.

  5. #5
    . MrExcel's Avatar
    Join Date
    Feb 2002
    Location
    Merritt Island Florida
    Posts
    872
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Convert to Proper case with VBA

    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
    View a collection of recent Excel articles in the Excel Daily News

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •