VBA code to capitalize the text in selected cells in an Excel worksheet


 Option Explicit


Sub CapitalizeSelectedData()

    ' Capitalize the text in the selected cells

    

    Dim cell As Range

    For Each cell In Selection.Cells

        cell.Value = StrConv(cell.Value, vbProperCase)

    Next cell

End Sub


This code defines a subroutine CapitalizeSelectedData that capitalizes the text in the currently selected cells using the StrConv function with the vbProperCase argument. This function capitalizes the first letter of each word in the text, while leaving the rest of the letters lowercase. To use this code, simply select the cells containing the text you want to capitalize, and then run the CapitalizeSelectedData macro.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.