2

I have an Excel file and a userform where user can type in students' details and the form will check for duplication and then add the info onto the last line of a table. I want to improve it further by making the form capitalize the first letter of each name using this code:

Me.Surname.Value = StrConv(Me.Surname.Value, vbProperCase)

Me.Surname.Value is the input of the form, mostly Vietnamese such as Trần, Nguyễn, Thảo, etc. However, they are changed into something like Tr?n, Nguy?n, Th?o after going through StrConv. I read some suggestions and change my locale to Vietnamese but the problem persists.

Do you have any suggestion to fix this? I am thinking of converting the inputs into hex value and then write them down using ChrW(), but I can't find a way to do that.

1
  • You would need to use StrConv() to convert the string from whatever encoding it uses, or include a locale maybe. Commented Sep 29, 2021 at 12:58

1 Answer 1

1

I played a bit with this and the culprit seems to be StrConv. It works for me if instead of using StrConv I explicitely set the proper case:

Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(Surname.Text, 2)

or even more precise:

Surname.Text = UCase(Left(Surname.Text, 1)) & Mid(LCase(Surname.Text), 2)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It really seems like StrConv is what went wrong. I am new to VBA, so I didn't know about UCase and LCase. With this, I can make everything work now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.