Macro change data in cell from lower case to uppercase

APML

Board Regular
Joined
Sep 10, 2021
Messages
216
Office Version
  1. 365
Hi all. I'm not so great at macros or vba. I generally get through by finding bits and pieces on the net and getting it to work.
I have the following code which I've used in another of my sheets.
Can some pls advise how I turn this into a stand-alone macro?


If Not (Application.Intersect(Target, Range("B3")) _

Is Nothing) Then

With Target

If Not .HasFormula Then

Application.EnableEvents = False

.Value = UCase(.Value)

Application.EnableEvents = True
End If

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Maybe something like

Option Explicit

VBA Code:
'************************************************
' By: dave3009                                  *
' Date: 2022-09-19                              *
' Purpose: Convert selected cells to upper case *
'************************************************

Sub ConvertToUpper()
Dim c As Range                                      'Declare a cell range variable
For Each c In Selection.Cells                       'Loop each cell in the selection
    If Not c.HasFormula Then                        'Test we won't overwrite a formula
        c.Value = StrConv(c.Value, vbUpperCase)     'Convert the value to upper case
    End If
Next c                                              'Repeat
End Sub
 
Upvote 0
Hey firstly, thx for your help. I'm embarrassed about my lack of understanding of VBA (I keep telling myself I'll do a quick course but never seem to get around to it).
So here's my silly question.. There's only one cell I need to convert to uppercase (B3), in your VBA, where do I specify that cell?
 
Upvote 0
Try this
VBA Code:
Sub Make_B3_UCase()
    Range("B3") = [INDEX(UPPER(B3),)]
End Sub
 
Upvote 0
My code will wholesale convert anything that's selected to upper case. Usually if it's just one cell you'd leave it in the change event.

But try

VBA Code:
'************************************************
' By: dave3009                                  *
' Date: 2022-09-19                              *
' Purpose: Convert B3 cells to upper case       *
'************************************************

Sub ConvertToUpper()
Range("B3").Value = StrConv(Range("B3").Value, vbUpperCase)     'Convert the value to upper case
End Sub
 
Upvote 0
My code will wholesale convert anything that's selected to upper case. Usually if it's just one cell you'd leave it in the change event.

But try

VBA Code:
'************************************************
' By: dave3009                                  *
' Date: 2022-09-19                              *
' Purpose: Convert B3 cells to upper case       *
'************************************************

Sub ConvertToUpper()
Range("B3").Value = StrConv(Range("B3").Value, vbUpperCase)     'Convert the value to upper case
End Sub
So I've done this (as per instructions).. How do i get it as a change event (atm, I need to manually run it before it will change from lower to upper

1663547155424.png
 
Upvote 0
thx for your help, I've managed to solve it

Private Sub Worksheet_Change(ByVal Target As Range)
' Forces text to UPPER case for the cell B3
If Target.Address(0, 0) = "B3" Then
Application.EnableEvents = False
Target.Value = UCase(Target.Value)
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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