macro to change to uppercase

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
826
Office Version
  1. 365
Platform
  1. Windows
Hi
I use the following macro to change all the letters in a cell to uppercase.
HTML:
Sub Uppercase()
Selection.Name = "here"
   For Each x In Range("here")
      x.Value = UCase(x.Value)
      ActiveWorkbook.Names("here").Delete
      Next
End Sub
If the cell is merged, I get an error message referring to ActiveWorkbook.Names("here").Delete,
<?xml:namespace prefix = o /><o:p></o:p>
I tried to add
HTML:
  On Error:End Sub

But I can’t get it to work
<o:p></o:p>
What I’m I doing wrong
<o:p></o:p>
Mike
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I modified this and used it on a mix of merged and unmerged cells and it worked fine for me. Can you provide a sample of your data maybe and what you're selecting? It looks like you're deleting the name in your for loop, too.

Code:
Sub Uppercase()
    For Each c In Selection
      c.Value = UCase(c.Value)
    Next
End Sub
 
Upvote 0
Hi CWatts,

I made the macro way back when I was using Excel 2003. I don't remember why I had to first make a range name to have the macro work :confused:
Your code does exactly what I want :biggrin:

below is over 4 rows. 3 rows are merged on 5 lines for appearance sake!

<TABLE style="WIDTH: 330pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=440><COLGROUP><COL style="WIDTH: 60pt" width=80><COL style="WIDTH: 105pt; mso-width-source: userset; mso-width-alt: 3982" width=140><COL style="WIDTH: 60pt" width=80><COL style="WIDTH: 105pt; mso-width-source: userset; mso-width-alt: 3982" width=140><TBODY><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl68 height=26 width=80>Name</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 270pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl69 width=360 colSpan=3></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>Address</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 270pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl69 width=360 colSpan=3></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>City / State</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 270pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl69 width=360 colSpan=3></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>Home phone</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 105pt; BORDER-TOP: #89b8c1; BORDER-RIGHT: #f0f0f0" class=xl64 width=140></TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl63 width=80>Work phone</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: #eef6f6; WIDTH: 105pt; BORDER-TOP: #89b8c1; BORDER-RIGHT: #89b8c1 1pt solid" class=xl66 width=140></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>Cell phone</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 105pt; BORDER-TOP: #89b8c1; BORDER-RIGHT: #f0f0f0" class=xl64 width=140></TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl67 width=80>Fax</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: #eef6f6; WIDTH: 105pt; BORDER-TOP: #89b8c1; BORDER-RIGHT: #89b8c1 1pt solid" class=xl66 width=140></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>E-mail</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 270pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl69 width=360 colSpan=3></TD></TR><TR style="HEIGHT: 19.5pt; mso-height-source: userset" height=26><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #89b8c1 1pt solid; BACKGROUND-COLOR: transparent; WIDTH: 60pt; HEIGHT: 19.5pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #89b8c1 1pt solid" class=xl65 height=26 width=80>Notes</TD><TD style="BORDER-BOTTOM: #89b8c1 1pt solid; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: #eef6f6; WIDTH: 270pt; BORDER-TOP: #89b8c1 1pt solid; BORDER-RIGHT: #89b8c1 1pt solid" class=xl69 width=360 colSpan=3></TD></TR></TBODY></TABLE>


Thanks for your help :)

Mike :beerchug:
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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