Ucase code for specific range

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Hi,
I have the code shown below which changes small case to upper case.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub


    On Error Resume Next


    If Not Intersect(Target, Range("G13:O51")) Is Nothing Then


        Application.EnableEvents = False


        Target = UCase(Target)


        Application.EnableEvents = True


    End If


    On Error GoTo 0


End Sub

The range G13:O51 pretty much controls the whole sheet.
Can you advise the edit should i require the range L13:L18 & G21:G23 to not be included & stay as small case
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
What should happen if the target (which can be a multi-cell range) overlaps part of the range you want to upper case (this can occur when someone copy/pastes a multi-cell range of values)?
 
Upvote 0
I understand what you have advised and thanks.
The cell range in question will have text input into it and that’s it.

Nothing will be pasted into the cells in question & if anything does happen in the cells it will only be to reword the text.

Thanks.
 
Upvote 0
Okay, give this code a try...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    If Not Intersect(Target, Range("H13:K18,M13:O18,H19:O23,G13:G20,G24:O51")) Is Nothing Then
      Application.EnableEvents = False
      Target = UCase(Target)
      Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Hi,
That has allowed me to do what i require but im a little lost as to how it did it.
I mean L13:L18 & G21:G23 are not even mentioned in the code just ranges around it ?

could you explain please.
 
Upvote 0
Hi,
That has allowed me to do what i require but im a little lost as to how it did it.
I mean L13:L18 & G21:G23 are not even mentioned in the code just ranges around it ?

could you explain please.
The code tests for the intersection of the Target cell and the range of cells you want it to be able to change and allows them to be changed... there is no reason to test the cells that are to be ignored.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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