I have the following Private sub that is to ensure that the value entered in the cell will be all CAPS. When I use this, it just loops and never get to End Sub...
Any suggestions?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim UpperCaseSym As Range
Set UpperCaseSym = Range("B9")
If Target.Address = UpperCaseSym.Address Then
UpperCaseSym = UCase(UpperCaseSym)
End If
End Sub
Thanks
Gib
Try this
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$9" Then Target = UCase(Target)
End Sub
If it's only B9 that needs to be processed then Charle's code is perfect, but if you want to process another range you could use the worksheet change event together with the intersect command
If you change cells in a Change event, you should always disable events while you do so to avoid recursion:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim UpperCaseSym As Range
Set UpperCaseSym = Range("B9")
If Not Intersect(Target, UpperCaseSym) is nothing Then
application.enableevents = false
UpperCaseSym = UCase(UpperCaseSym)
application.enableevents = True
End If
End Sub
Was able to resolve this by turning off updates while the macro was in process:
Private Sub Worksheet_Change(ByVal Target As Range)
'This is to UPPERCASE the value entered in to the Ticker Cell
Dim UpperCaseSym As Range
Set UpperCaseSym = Range("B9")
If Target.Address = UpperCaseSym.Address Then
Application.EnableEvents = False ' Disable events to prevent a loop
UpperCaseSym.Value = UCase(UpperCaseSym.Value)
Application.EnableEvents = True ' Re-enable events
End If
End Sub
Thanks to all,
Gib