use range variable in command to set selected cells all uppercase

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
I want to select cells and turn them upper case. the cells selected will change each time.

I have tried a few things and had no luck

the first way it did not want to do it bc I think my use of the range variable in the actual command is not right.
HTML:
'set range based on selected cells
   Set Rng = Selection
'Loop to cycle through each cell in the specified range.
  For Each x In Range(Rng)
'Change the text in the range to uppercase letters.
     x.Value = UCase(x.Value)
  ' Next

then I saw where someone was able to use one line to take the selected cells and make them proper case...I tried to convert to upper case and it did not work
HTML:
Selection.Value = Application.UCase(Selection.Value)
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I tried it and it only works if you Dim x as range. So this worked for me:
Code:
Sub test()


Dim x As Range


    For Each x In Selection
        x = UCase(x)
    Next x
    
End Sub
 
Upvote 0
Heres a way:

Code:
Dim x As Variant

Set x = Selection
x = Evaluate("INDEX(UPPER(" & x.Address & "),0)")
Selection.Value = x

Not a one liner mind.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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