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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

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