• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to edit cell content without changing the format

AmruthSagar

New Member
Hi All,

I need a VBA code to capitalize first letter in the cell without changing the cell format or without changing the text colors (please refer sample file). As you can see in the sample file i have multiple text colors within the cell. These format should be maintained intact while capitalizing the first letter.

I tried doing this but the cell format is changing or it is successful if the entire text has single color. But that is not the case with my data.

So could anyone please help me with the macro. I would select the entire range of cell and run the macro.

Thanks a lot in advance.

Amruth
 

Attachments

  • Sample File.xlsx
    10.2 KB · Views: 5
Try
Code:
Sub test()
    Dim r As Range, m As Object
    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "((^|\.) *)([a-z])"
        For Each r In [a2].CurrentRegion
            If .test(r.Value) Then
                For Each m In .Execute(r.Value)
                    r.Characters(m.firstindex + Len(m.submatches(0)) + 1, 1).Text = UCase$(m.submatches(2))
                Next
            End If
        Next
    End With
End Sub
 
Back
Top