Convert Cell contents all to uppercase on exit

David_UK

Active Member
Joined
Mar 18, 2003
Messages
299
I have a workbook that I want to either, have the cells I enter in the range to be all formatted to uppercase if text, or that when the book is saved, it converts all cells within specific ranges to uppercase when saved.

Either way, before the book is saved, I want it to convert so for example,

Column A is all dates,
Column B is codes, i.e. c01-ret356-eet-01
Column C is say a name i.e. David

So for columns B and C either on leaving the cell via enter or other means the cell will auto uppercase, or when the workbook is saved, it will ask the user to accept the changes...

I prefer the first choice if easier.

thanks,

David.
 
Reenable events as detailed earlier. For multiple cell changes:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim cell As Range, iRange As Range
  Set iRange = Intersect(Target, Range("C4:C18900"))
  If iRange Is Nothing Then Exit Sub
  Application.EnableEvents = False
  For Each cell In iRange
      cell = UCase(cell)
  Next cell
  Application.EnableEvents = True
End Sub
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Thanks Ken, however, I decided to ditch the ranged cells because I have many columns that I need this function to work on, can you redo this function so that any cell when changed within the worksheet is changed this happens? Or will this do it?

Here was the original.

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Target = UCase(Target)
Application.EnableEvents = True
End Sub

thanks,

David.
 
Upvote 0
Just remove the top bit that checks the cell range

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim cell As Range

Application.EnableEvents = False

For Each cell In Target.Cells
cell = UCase(cell)   
Next cell   
Application.EnableEvents = True 

End Sub
 
Last edited:
Upvote 0
Adam's code should work. Put this into the Immediate window and press Enter at the end.
Code:
Application.EnableEvents = True

And this code in the sheet's code of course.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim cell As Range
  Application.EnableEvents = False
  For Each cell In Target
      cell = UCase(cell)
  Next cell
  Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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