Excel – Capitalizing first letter of strings

excelvba

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
Next

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)
Next

or without a loop:

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