Only run VBA code on cells that have values

NORRILLOUS

New Member
Joined
Apr 10, 2014
Messages
36
Office Version
  1. 365
Platform
  1. Windows
I found a script online that I have been using for sometime now and it works very well. All it does is go through a range A2:A1000 and changes every lower case letter to upper case. The issue I have is it really slows things down when I am trying to work and save. I would like to know is it possible to change it to only look at the cells that have values? Current code is below;

VBA Code:
' Loop to cycle through each cell in the specified range.
      For Each x In Range("A2:A500")
' Change the text in the range to uppercase letters.
      x.Value = UCase(x.Value)
   Next

Thank you in advance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,583
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
If your range is constants and not formulas see if the code below is any faster...
VBA Code:
Sub ucseA()
  With Range("A2", Cells(Rows.Count, "A").End(xlUp))
    .Value = Evaluate("IF(" & .Address & "="""","""",UPPER(" & .Address & "))")
  End With
End Sub
 

NORRILLOUS

New Member
Joined
Apr 10, 2014
Messages
36
Office Version
  1. 365
Platform
  1. Windows
If your range is constants and not formulas see if the code below is any faster...
VBA Code:
Sub ucseA()
  With Range("A2", Cells(Rows.Count, "A").End(xlUp))
    .Value = Evaluate("IF(" & .Address & "="""","""",UPPER(" & .Address & "))")
  End With
End Sub

Works Perfect and there is virtually no delay!!! Thank again!
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,583
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You're welcome
 

Forum statistics

Threads
1,175,530
Messages
5,897,952
Members
434,688
Latest member
vi28

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
Top