Auto-Capitalizing

helga1980

New Member
Joined
Aug 11, 2011
Messages
16
I found some code to auto-capitlize in a worksheet...what do I have to do so that it doesn't apply the auto-capitalization of the existing text to the whole sheet??

Sub ChangeCase()
Dim Rng As Range
On Error Resume Next
Err.Clear
Application.EnableEvents = False
For Each Rng In Selection.SpecialCells(xlCellTypeConstants, _
xlTextValues).Cells
If Err.Number = 0 Then
Rng.Value = StrConv(Rng.Text, vbUpperCase)
End If
Next Rng
Application.EnableEvents = True
End Sub

Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Change the range at this point here.

Code:
For Each Rng In [COLOR=red]Selection.SpecialCells(xlCellTypeConstants, _[/COLOR]
[COLOR=red]xlTextValues).Cells[/COLOR]

The code you posted works off of the selected range prior to running the macro. You could change the range to be, for example, A1:A50.

Ex:
Code:
Sub ChangeCase()
Dim Rng As Range, myRange as Range
On Error Resume Next
Err.Clear
Application.EnableEvents = False
Set myRange = Range("A1:A50")
For Each Rng In myRange.SpecialCells(xlCellTypeConstants, _
xlTextValues).Cells
If Err.Number = 0 Then
Rng.Value = StrConv(Rng.Text, vbUpperCase)
End If
Next Rng
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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