Column To Upper() - In place

Sky_B

New Member
Joined
Mar 14, 2016
Messages
6
Is this possible? I'm trying to create a Macro command that will convert a column to upper() without creating a new column and using a =UPPER() formula in the new column.

So far I have this to select the column(s) that are currently active.
Code:
Selection.EntireColumn.Select

I would like to say something like
Code:
Selection.EntireColumn.Select
Selection.UPPER = Selection.EntireColumn.Select

Something along those lines anyway. Is this possible?

Thanks
Sky
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to the board.

Try something like
Code:
Sub test()
Dim MyArray As Variant, i As Long
With Application.Intersect(Selection.EntireColumn, ActiveSheet.UsedRange)
    MyArray = .Value
    For i = LBound(MyArray) To UBound(MyArray)
        MyArray(i, 1) = UCase(MyArray(i, 1))
    Next i
    .Value = MyArray
End With
End Sub
 
Upvote 0
PERFECT!!!!!!

Thank you so much. This will save a ton of time.
Is there an "Answered" or something to say this post has been answered somehow?

thanks again,
Sky
 
Upvote 0
Welcome to the board.

Try something like
Code:
Sub test()
Dim MyArray As Variant, i As Long
With Application.Intersect(Selection.EntireColumn, ActiveSheet.UsedRange)
    MyArray = .Value
    For i = LBound(MyArray) To UBound(MyArray)
        MyArray(i, 1) = UCase(MyArray(i, 1))
    Next i
    .Value = MyArray
End With
End Sub
You can also do it without using a loop (nor restricting the selection to the UsedRange)...
Code:
[table="width: 500"]
[tr]
	[td]Sub MakeUpper()
  Selection = Evaluate(Replace("IF(@="""","""",UPPER(@))", "@", Selection.Address))
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Could the same code be used to replace a string within each cell of a column?

Using the Replace to change say "The dog" to "The cat" in every occurrence in a column?
So not changing the content to UPPER but simply replacing without looping?

Thanks,
sky
 
Upvote 0
Could the same code be used to replace a string within each cell of a column?

Using the Replace to change say "The dog" to "The cat" in every occurrence in a column?
So not changing the content to UPPER but simply replacing without looping?
Is "The dog" the only text in the cell? What about letter casing... would "the dog" be replaced by "The cat" as well?
 
Upvote 0
No, it's not the only text in the field.
My end game is to convert the column to UPPER and then replace (more accurately "remove") specific text from the cell.

Convert: New Member $5 Free Play
To: $5 FREE PLAY

Each cell in the row contains: New Member
The rest of the text in the cell is variable.

I was trying to learn it but with so many ways to do something I was getting lost.

Any thoughts on how to accomplish this?

Thanks,
Sky
 
Upvote 0
I feel like I'm close with this but keep getting #VALUE when I run it. Any thoughts?
Code:
 Selection = Evaluate(Replace("IF(@="""","""",UPPER(REPLACE(@,1,11,"")))", "@", Selection.Address))

If i'm thinking correctly, this evaluates
IF @ (cell data) is blank then leave blank
ELSE convert to REPLACE @ (cell data) starting with the 1st character through the 11th character with nothing ("")
THEN convert to UPPER
FINALLY take @ and write it back into Selection.Address (cell)

Is this pretty close?

thanks,
sky
 
Upvote 0
Why not just remove the text and then use the formula Rick provided?
Code:
Sub test()
With Selection
    .Replace "New Member ", ""
    .Value = Evaluate(Replace("IF(@="""","""",UPPER(@))", "@", Selection.Address))
End With
End Sub
 
Upvote 0
Works like a charm. Thank you.
I was using what Rick gave me and trying to adjust it slightly. The formula works when not used as VBA code but instead as an excel formula inside a cell.
Thank you guys so much for being active and nice.

Sky
 
Upvote 0

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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