VBA code to change text entered in cell to uppercase

KMH

New Member
Joined
Nov 10, 2022
Messages
23
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have several cells in a worksheet that I would like to have automatically change to uppercase once information is entered in the cells.

I've tried the below, but it isn't working for me:

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("B4,G3,F7:H15,F23,C27,E27,F46:G50,G74:I79,C91,E95")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Value = UCase(Target.Value)
Application.EnableEvents = True

End Sub


I'd be grateful for any other suggestions as to code I could try.

Thanks,
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Using your code, if I enter text in cell B3, it is changed to upper case. If I enter text in cell B4, the case is not changed.

What do you mean by "isn't working"?
 
Upvote 0
Using your code, if I enter text in cell B3, it is changed to upper case. If I enter text in cell B4, the case is not changed.

What do you mean by "isn't working"?
It doesn't change text in the defined range to uppercase
 
Upvote 0
The one below works, but I have to manually run it. It doesn't do it automatically as I come out of the cell. Also it's running the loop for a while.

Ideally, I'd like for the text in the cell to change as soon as I exit the cell and without having to create a macro button for it.

Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("B4, G3, F7:H15, F23, C27, E27, F46:G50, G74:I79, C91, E95")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.Value)
Next
End Sub
 
Upvote 0
TEST 1 CSPR Sub-Committee Points Schedule Calculator UNLOCKED v2.xlsm
ABCDEFGHIJ
1Permanent Residence Points Assessment
2
3File Number:000000Agent:
4Name:LAST NAME, FIRST NAME
5
6Total Points:0.00Dependants:D.O.B.
7
8Factor 1:0.00
9Factor 2:0.00
10Factor 3:0.00
11Factor 4:0.00
12Factor 5:0.00
13Factor 6:0.00
14Factor 7:0.00
15Factor 8:0.00
16Factor 9:0.00
17Deductibles:0.00
18
19
20
21Factor 1 - Occupation0/15
22
23Currently employed?NOccupation:
24
25Factor 2 - Education, Training & Experience0.00/25
26Start DateDate of Application
272a.Years of experience0.00
28
292b.Education:None of the above0
30
31Factor 3 - Local Investments0.00/30
321. Investment in Property0.00
332. Investment in a locally licensed company0.00
343. Combined (in the event that neither 1 or 2 meets the minimum criteria individually)0.00
35
36Applicant:12 month IncomeNo. of persons that jointly own the property(ies) (including the applicant)0
375 yr Income
38Annual Income
39
40Spouse:12 month IncomeProperty jointly owned with spouse:N
415 yr Income
42Annual Income
43
4490% of 12 mth income$0.00Property Details
4540% of 5 yr Income$0.00BlockParcel
46
47Children: N
48# on non-accompanying dependant children00
49# of accompanying dependant children (school age)00
50# of accompanying dependant children (non-school age)00
51
52OPTION 1OPTION 2
53Property - purchase priceProperty - down payment
54Stamp DutyStamp Duty
55Mortgage amount owingPayments to date
56Total$0.00Total$0.00
57
58Investment in Local Company$0.00
59
60Factor 4 - Financial Stability0.00/30
61Savings$0.000.0000
62Salary & Income$0.000
63
64
65
66
67Factor 5 - Community Involvement0.00/20
68# of Years# of Hours Per Year
691a. Training &/or Mentoring of Caymanians outside of normal work hours or related employer sponsored activities0
701b. Personal sponsorship of a Caymanian's tertiary training >$3,500 p/a0
711c. Actively assist in the Rehabilitation & Mentoring of Offenders00
72
732a. Participation & Assistance in a Youth Programme0Name(s) of Persons Entities:Section
742b. Training & Mentoring of Caymanians within normal work related / sponsored activities0
752c. Participation and assistance in a sports programme0
762d. Participation and assistance in an arts programme0
772e. Participation and assistance in a local service club activities0
782f. Participation and assistance in a local church programme activities0
792g. Personal donations to community minded activities of a minimum of $2,000 p/a0
802h. Volunteering for non-profit, charitable or voluntary organisations00
81
82Factor 6 - History and Culture Test0.0/20
83Test Results/40
84
85Factor 7 - Possessing Close Caymanian Connections0/100
86
87Parent or Child of a CaymanianN0
88Sibling or Grandparent of a CaymanianN0
89
90Factor 8 - Demographic and Cultural Diversity0/10
91Nationality
92
93Factor 9 - Age Distribution0/10
94Date of Birth
95Age at Date of Application0
96
97Deductible Components0
98Explanation# of Points Deducted
99Criminal ConvictionsN
100Health IssuesN
101Administrative fines levied in relation to statutory offensesN
102Lack of reasonably funded pension planN
103Other mitigating FactorsN
104
105
106
107Comments:
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
ASSESSMENT
Cell Formulas
RangeFormula
B6B6=SUM(B8:B16)-B17
B8B8=I21
B9B9=I25
B10B10=I31
B11B11=I60
B12B12=I67
B13B13=I82
B14B14=I85
B15B15=I90
B16B16=I93
B17B17=I97
I21I21=IF(OR(C23="",C23="N"),0,15)
I25I25=H27+H29
H27H27=IF((Calculations!E16+(Calculations!E17/12))<10,Calculations!E16+(Calculations!E17/12),10)
H29H29=VLOOKUP(C29,Calculations!A2:B9,2, FALSE)
I31I31=IF(($H$32+$H$33+$H$34>30),30,IF($H$32+$H$33+$H$34<30,$H$32+$H$33+$H$34,0))
H32H32=IF(VLOOKUP(MAX(Calculations!$I$2:$I$5), Calculations!$I$2:$I$5,1,0)>30,30,VLOOKUP(MAX(Calculations!$I$2:$I$5), Calculations!$I$2:$I$5,1,0))
H33H33=IF(VLOOKUP(MAX(Calculations!$I$8:$I$9), Calculations!$I$8:$I$9,1,0)>30,30,VLOOKUP(MAX(Calculations!$I$8:$I$9), Calculations!$I$8:$I$9,1,0))
H34H34=IF(VLOOKUP(MAX(Calculations!$I$12:$I$15), Calculations!$I$12:$I$15,1,0)>30,30,(VLOOKUP(MAX(Calculations!$I$12:$I$15), Calculations!$I$12:$I$15,1,0)))
C44C44=IF($G$40="Y",(((($C$36+$C$40)*0.9)*5)*0.4),((($C$36*0.9)*5)*0.4))
C45C45=IF($G$40="Y",(($C$37+$C$41)*0.4),($C$37*0.4))
D48D48=IF($C$48>0,2500*$C$48,0)
D49D49=IF($C$49>0,15000*$C$49,0)
D50D50=IF($C$50>0,12000*$C$50,0)
C56C56=IF(AND($G$36>2,$G$40="Y"),(($C$53+$C$54-$C$55)/$G$36)*2,IF(AND($G$36>1,$G$40="N"),(($C$53+$C$54-$C$55)/$G$36),$C$53+$C$54-$C$55))
H56H56=IF(AND($G$36>2,$G$40="Y"),(($H$53+$H$54+$H$55)/$G$36)*2,IF(AND($G$36>1,$G$40="N"),(($H$53+$H$54+$H$55)/$G$36),$H$53+$H$54+$H$55))
I60I60=IF((H61+H62)>30,30,H61+H62)
E61E61=IF(C61>0,(C61/C36)*100,0)
F61F61=IF(E61<1,0,IF(E61<1.99,3,IF(E61<2.99,6,IF(E61<3.99,9,IF(E61<4.99,12,IF(E61>=5,15,0))))))
C62C62=IF(AND($C$47="Y",$D$48+$D$49+$D$50>0),($C$38+$C$42)-($D$48+$D$49+$D$50),IF(AND($C$47="N",$D$48+$D$49+$D$50>0),$C$38-($D$48+$D$49+$D$50),$C$38))
H61H61=Calculations!$A$17
H62H62=IF($C$62<15000,0,IF($C$62<29999,1,IF($C$62<39999,3,IF($C$62<49999,5,IF($C$62<59999,7,IF($C$62<69999,9,IF($C$62<89999,11,IF($C$62<109999,12,IF($C$62<129000,13,IF($C$62<149999,14,IF($C$62>150000,15)))))))))))
I67I67=IF((H71+H80)>20,20,H71+H80)
F69:F71F69=IF(AND(C69>0,D69>=35),C69*2,IF(AND(C69>8,D69>=35),16,0))
H71H71=SUM(F69:F71)
F73:F80F73=IF(AND(C73>0,D73>=35),C73*1.5,IF(AND(C73>8,D73>=35),16,0))
H80H80=SUM(F73:F80)
I82I82=C83/2
I85I85=D87+D88
D87D87=IF(C87="Y",40,0)
D88D88=IF(C88="Y",20,0)
I90I90=Calculations!A29
I93I93=Calculations!D23
C95C95=IF(OR(ISBLANK(E95),ISBLANK(E27)),0,DATEDIF(E95,E27,"y"))
I97I97=SUM($H$99:$H$103)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B6Expression=$B$6<110textNO
B6Expression=$B$6>=110textNO
Cells with Data Validation
CellAllowCriteria
C47List=Factor3
C87:C88List=Factor3
C99:C103List=Factor3
G40:G41List=Factor3
C27Datebetween 1/1/1900 and TODAY()
E27Datebetween 1/1/1900 and TODAY()
C69:C71Any value
C73:C80Any value
C23List=Factor1
J74:J79List=Factor5
E95Any value
H7:H15Any value
F36:F38Any value
G36:G38Whole number>=0
C91Any value
C29:F29List=Calculations!$A$2:$A$9
 
Upvote 0
It doesn't change text in the defined range to uppercase

That's because the code is written to exclude the defined range. That is, it will change B3, but not B4. If you mean for the range to be inclusive, then change to something like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range, R As Range

    Set MyRange = Intersect(Target, Me.Range("B4,G3,F7:H15,F23,C27,E27,F46:G50,G74:I79,C91,E95"))
    If Not MyRange Is Nothing Then
        Application.EnableEvents = False
        For Each R In MyRange
            R.Value = UCase(R.Value)
        Next R
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution
That's because the code is written to exclude the defined range. That is, it will change B3, but not B4. If you mean for the range to be inclusive, then change to something like this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim MyRange As Range, R As Range

    Set MyRange = Intersect(Target, Me.Range("B4,G3,F7:H15,F23,C27,E27,F46:G50,G74:I79,C91,E95"))
    If Not MyRange Is Nothing Then
        Application.EnableEvents = False
        For Each R In MyRange
            R.Value = UCase(R.Value)
        Next R
        Application.EnableEvents = True
    End If
End Sub
Thank you sooooooo much!!!!!!!!!!!!!!!!! That worked perfectly!!!!!!!!!!!
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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