Macro to Capitalize Colum on Save

Mr Jukebox

New Member
Joined
Sep 25, 2008
Messages
36
Looking for a Macro that will capitalize any letters in the C column when the workbook is saved. The macro I have will capitalize the C column of whichever sheet I am working in when I saved it. I want it to only capitalize the C column in the "Main" worksheet no matter what worksheet is currently open when saved.

Thanks in advance
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
This will convert "abc" to "ABC"
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    lr = Worksheets("Main").Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        Worksheets("Main").Range("C" & i).Value = UCase(Worksheets("Main").Range("C" & i).Value)
    Next i
End Sub


if you want to convert "abc" to "Abc" then you can use this:
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    lr = Worksheets("Main").Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To lr
        Worksheets("Main").Range("C" & i).Value = StrConv(Worksheets("Main").Range("C" & i).Value, vbProperCase)
    Next i
End Sub
 
Upvote 0
This macro works I just had to change the opening line to "Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)" so that it runs whenever the workbook is saved instead of only running when it is closed. Thank you for your assistance.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top