Excel – Capitalizing first letter of strings


I am trying to capitalize the first letter string sent in the array arr. The part of the code that does not work is the Right function, which causes the code to return an error. What could be the fix?

For Each sent In arr
    sent = UCase(Left(sent, 1)) & Right(sent, Len(sent) - 1)
    arr(i) = sent
    i = i + 1

Best Solution

You can just use the StrConv() function for this. e.g. :

For i = LBound(arr) To UBound(arr)
   sent = arr(i)
   arr(i) = StrConv(sent, vbProperCase)

or without a loop:

arr = Split(StrConv(Join$(arr, " "), vbProperCase), " ")
Related Question