VBA ucase code question

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Evening.
I have this working code below

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Column = 14 Then Exit Sub
        If .Count = 1 And Not .HasFormula Then
            Application.EnableEvents = False
            .Value = UCase(.Value)
            Application.EnableEvents = True
        End If
    End With
End Sub

I would like to have the upper case text only apply to the range G13:O42

I then input this line Range("G13:O42").Value = UCase(.Value) so code now shown below but what i found was what if i wrote DOG in cell L31 the word DOG would be inserted into every cell within the range.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)    With Target
        If .Column = 14 Then Exit Sub
        If .Count = 1 And Not .HasFormula Then
            Application.EnableEvents = False
            Range("G13:O42").Value = UCase(.Value)
            Application.EnableEvents = True
        End If
    End With
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try:

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(Target, Range("G13:o42")) Is Nothing Then
   With Target
        If .Column = 14 Then Exit Sub
        If .Count = 1 And Not .HasFormula Then
            Application.EnableEvents = False
            .Value = UCase(.Value)
            Application.EnableEvents = True
        End If
    End With
End If
End Sub
 
Upvote 0
Hi,
I would say that had no affect,whether i type small or upper case it stays the same as i type.
My aim is within the range whatever i type will be upper case but outside the range will be lower case.

Thanks
 
Upvote 0
If a value was copied into more than one cell in that range, the macro would not run. I would write it like this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range
Set d = Intersect(Target, Range("G13:O42"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
    For Each c In d
        If c.Column <> 14 Then
            If Not c.HasFormula Then c = UCase(c)
        End If
    Next
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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