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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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