Thread: Uppercase
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Uppercase

Private Sub Worksheet_Change(ByVal Target As Range)
Target.Value = UCase(Target.Value)
End Sub



You should use Application.EnableEvents to prevent looping:


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

Without disabling events, changing a cell causes Change to run, which
changes the cell, which causes Change to run, which changes the cell,
which causes Change to run, and on and on until VBA gives up.

EnableEvents = False prevents this looping by indicating to Excel that
it should not trigger any events. EnableEvents = True restores normal
behavior.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]




On Thu, 6 May 2010 09:05:01 -0700, Brad
wrote:


Private Sub Worksheet_Change(ByVal Target As Range)
Target.Value = UCase(Target.Value)
End Sub