Apply ProperCase to dynamic range in a column

Vincent88

Active Member
Joined
Mar 5, 2021
Messages
382
Office Version
  1. 2019
Platform
  1. Windows
  2. Mobile
Hi, Appreciate any help to modify the code to apply the function to the dynamic range in a column only not whole column ?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim LastRow As Long
LastRow = Range("L2").End(xlDown).Row

If Target.Cells.Count > 1 Then Exit Sub
On Error GoTo ErrHandler:

If Target.Column = 12 Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = StrConv(Target.Text, vbProperCase)
Application.EnableEvents = True
End If
End If
ErrHandler:
Application.EnableEvents = True
End Sub
 
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim LastRow As Long
LastRow = Range("L2").End(xlDown).Row

If Target.CountLarge > 1 Then Exit Sub
On Error GoTo ErrHandler:

If Not Intersect(Target, Range("L2:L" & LastRow)) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = StrConv(Target.Text, vbProperCase)
Application.EnableEvents = True
End If
End If
ErrHandler:
Application.EnableEvents = True
End Sub
 
Upvote 0
Solution

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
HI Fluff, Thanks. Your code works. Meantime I have another Uppercase function in any other range. The code works also but I wonder if my code can be modified more neatly. (Like
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

Select Case Sh.Name
    Case "Data"
      Exit Sub
    Case Else
  End Select

'ProperCase in Column A

Dim LastRow As Long
LastRow = Range("A3").End(xlDown).Row


If Target.CountLarge > 1 Then Exit Sub
On Error GoTo ErrHandler:

If Not Intersect(Target, Range("A3:A" & LastRow)) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = StrConv(Target.Text, vbProperCase)
Application.EnableEvents = True
End If
End If
'ErrHandler:
'Application.EnableEvents = True

'UpperCase From Range(C:AG)
If Target.CountLarge > 1 Then Exit Sub
On Error GoTo ErrHandler:
If Not Intersect(Target, Range("C3:AG" & LastRow)) Is Nothing Then
If Not IsNumeric(Target.Value) Then
Application.EnableEvents = False
Target.Value = UCase(Target.Text)
Application.EnableEvents = True
End If
End If
ErrHandler:
Application.EnableEvents = True



End Sub
If Target.CountLarge > 1 Then Exit Sub. I have to write this twice)
 
Upvote 0
There is no need to use this twice
VBA Code:
If Target.CountLarge > 1 Then Exit Sub
also you can get rid of the 2nd occurrence of
VBA Code:
On Error GoTo ErrHandler:
 
Upvote 0
Hi Fluff, Is it possible to amend the code run as array in order to run faster ! Current situation is that there is time lagging whenever I make input. I saw a youtube which demonstrated this method. Thanks on advance.
 
Upvote 0
There is nothing to put into an array, it just changes a single cell.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,123
Members
452,381
Latest member
Nova88

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