VBA - Applying PROPER format to range

Fishboy

Well-known Member
Joined
Feb 13, 2015
Messages
4,267
Hi all,

In my Excel 2010 workbook I have a Workbook_BeforeClose event which applies a number of formatting rules across the sheet to maintain a level of uniformity. It is all working well as is, however the recent addition of applying the PROPER case formatting function has slowed things down a bit and I expect it is because of the For Each Cell in Rng part. Please see the offending bit of code highlighted in bold red below:

Rich (BB code):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Dim rng As Range, cell As Range
        Set rng = Range("A3:A1500")
        For Each cell In rng
            cell.Value = WorksheetFunction.Proper(cell.Value)
        Next cell
    Range("A3:AI1500").Select
        With Selection.Font
        .Name = "Calibri"
        .Size = 11
        .Color = vbBlack
        End With
    Worksheets("Drivers").Range("A3:AI1500").HorizontalAlignment = xlCenter
    Worksheets("Drivers").Range("B3:B1500").NumberFormat = "0#### ######"
    Worksheets("Drivers").Range("A3:AI1500").Borders.LineStyle = xlContinuous
    Worksheets("Drivers").Range("A3:C1500").BorderAround _
    Weight:=xlMedium
    Worksheets("Drivers").Range("H3:L1500").BorderAround _
    Weight:=xlMedium
    Worksheets("Drivers").Range("M3:X1500").BorderAround _
    Weight:=xlMedium
    Worksheets("Drivers").Range("Y3:AI1500").BorderAround _
    Weight:=xlMedium
    Range("A1").Select
    MsgBox "All formatting has been made uniform.  Please remember to save."
End Sub

Even with Application.Screenupdating set to False, the screen still flickers and the whole process takes about 15 or so seconds, up from the 2 or so seconds it used to be before adding in this bit of code.

What I would like to know is if there is a better way of applying PROPER to those 1497 cells without having to loop through each cell in turn? Is it possible to apply the rule to the whole range in it's entirety?

While we are at it, if anyone can think of a more streamlined way of achieving the desired results of the code in another way I am all ears.

Any help is greatly appreciated.
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this.
Code:
Set Rng = Range("A3:A1500")

With Rng
    .Value = Evaluate("INDEX(PROPER(" & .Address & "),,1)")
End With
 
Upvote 0
Try this.
Code:
Set Rng = Range("A3:A1500")

With Rng
    .Value = Evaluate("INDEX(PROPER(" & .Address & "),,1)")
End With
Awesome! Thanks Norie. That is lightning quick again, really appreciate the help.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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