The following VBA macro that Bing AI provided does not work in excel 2010 - Why?
It is supposed to capitalize first letter of first word in sentence, following period & space in text- ex :
the rain in Spain. stays mainly in the plain.
result:
The rain in Spain. Stays mainly in the plain.
While there seems nothing wrong with this (none that I can say) it throws errors, ex. "Invalid procedure call or argument".
Any assistance much appreciated.
Thanks!
It is supposed to capitalize first letter of first word in sentence, following period & space in text- ex :
the rain in Spain. stays mainly in the plain.
result:
The rain in Spain. Stays mainly in the plain.
VBA Code:
Sub UppercaseAfterPeriodMultipleCells()
Dim rng As Range
Dim cell As Range
Dim txt As String
Dim i As Long
' Set the range to the cells you want to change
Set rng = ThisWorkbook.Sheets("Sheet1").Range("A1:A10")
For Each cell In rng
txt = cell.Value
' Convert the first character of the text to uppercase
txt = UCase(Left(txt, 1)) & Right(txt, Len(txt) - 1)
' Loop through the rest of the text
For i = 1 To Len(txt)
' If the character is a period, convert the next character to uppercase
If Mid(txt, i, 1) = "." Then
txt = Left(txt, i) & " " & UCase(Mid(txt, i + 2, 1)) & Right(txt, Len(txt) - i - 2)
End If
Next i
' Write the changed text back to the cell
cell.Value = txt
Next cell
End Sub
While there seems nothing wrong with this (none that I can say) it throws errors, ex. "Invalid procedure call or argument".
Any assistance much appreciated.
Thanks!