Hi everyone. I'm stuck on how to get this to work. Column M in my worksheet is used for U.S. state codes. If someone entering data into a cell in column M in the worksheet enters ca for California, the text should be converted to uppercase as soon as the cell is exited (it should read CA upon exit).

The code below does not work. I have it in a module. I have some code written in a worksheet_change event that does work, but I want to learn how to get it to work if I place it in a module. I'm trying to learn VBA and I just can't seem to grasp this concept.


Sub StatesUpperCase()

Application.ScreenUpdating = False

Dim Cell As Range

If Sheets(Sheet2).Active = True Then

For Each Cell In Range("$M$1:" & Range("$M$1").SpecialCells(xlLastCell).Address)
If Len(Cell) > 0 Then Cell = UCase(Cell)
Next Cell
Application.ScreenUpdating = True
End With
End If

End Sub