column uppercase

hendrikbez

Board Regular
Joined
Dec 13, 2013
Messages
95
Office Version
  1. 2021
Platform
  1. Windows
Hi i want to add button on sheet1, to make all words in sheet4 column c in upper case, this is the code i have.

How do I add a sheet to it.

VBA Code:
Private Sub Worksheet_Activate()
On Error Resume Next
Application.ScreenUpdating = False

Dim cell As Range

For Each cell In Range("$C$2:" & Range("$C$2").SpecialCells(xlLastCell).Address)
    cell.Value = UCase(cell.Value)
Next cell

On Error GoTo 0
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
With Worksheet_Activate code, you don't add the sheet to the code, you add the code to the sheet or run it with a buton.

Select the other sheet that you want to use the code with, then right click the sheet name (in excel) and click 'view code'. Paste your code into that module.

Go back to excel, then save the workbook (as macro enabled). To run the code for the first time, you will need to select another sheet, then re-select the sheet with the code.
 
Upvote 0
Hi hendrikbez,

the code right now applies the upper case to column C in the currently active sheet.

You want to address the sheet like this:
VBA Code:
For Each cell in Worksheets("Sheet4").Range("$C$2:" & Worksheets("Sheet4").Range("$C$2").SpecialCells(xlLastCell).Address)

@jasonb75 is right, though, you need the correct module for your code. If you want a button on Sheet 1, you need to put the code in the sub for the button, which is located in a general module and assign that sub to the button.

Regards,
Elaszat
 
Upvote 0
jasonb75 and Elaszat, thank your for your exlpantion, I have got it working.
 
Upvote 0
In case you might be interested, you do not need a loop to do what your code is doing.
VBA Code:
Private Sub Worksheet_Activate()
  With Range("C1", Cells(Rows.Count, "C").End(xlUp))
    .Value = Evaluate("IF(" & .Address & "="""","""",UPPER(" & .Address & "))")
  End With
End Sub
 
Upvote 0
Wow, that's really cool. Thanks for the interesting snippet, Rick! :biggrin:(y)
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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