One way:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim RngUCase As Range
Dim RngProper As Range
Set RngUCase = Me.Range("j5:j40,d5:d40")
Set RngProper = Me.Range("g5:g40")
Set Target = Target.Cells(1) 'just one cell
On Error GoTo Err_Handler:
Application.EnableEvents = False
With Target
If .HasFormula Then
'skip it
ElseIf Not Intersect(.Cells, RngUCase) Is Nothing Then
'in the upper case range
.Value = StrConv(.Value, vbUpperCase)
ElseIf Not Intersect(.Cells, RngProper) Is Nothing Then
'in proper case range
.Value = StrConv(.Value, vbProperCase)
End If
End With
ExitHere:
Application.EnableEvents = True
Exit Sub
Err_Handler:
MsgBox Err.Description, vbCritical, "Error " & Err.Number
Resume ExitHere
End Sub
Hi all small problem.
I have 3 ranges, 2 of those ranges I want to convert to UPPER case and one I
want to be proper case.
I have the UPPERCASE done how do I add the next range g5:g40 to make that
proper case... thanks see below
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rg As Range
On Error GoTo Err_Handler
Set rg = [j5:j40 , d5:d40] 'limit the range here
If Intersect(Target(1, 1), rg) Is Nothing Then Exit Sub
Application.EnableEvents = False
With Target(1, 1)
.Value = UCase(.Value)
End With
ExitHere:
Application.EnableEvents = True
Exit Sub
Err_Handler:
MsgBox Err.Description, vbCritical, "Error " & Err.Number
Resume ExitHere
End Sub