Rounding a named range with 68,880 cells

Bernieg

Board Regular
Joined
Jan 1, 2009
Messages
146
Office Version
  1. 365
Platform
  1. Windows
i'm trying to round named range cells to 3 decimal places to ensure files are not to big.
Named range: "Pod", 1435 rows by 48 column's = 68880 cells

The code below takes 35.75 seconds to run.

Question can it be done faster ?

Regards Bernie


VBA Code:
Sub Rounding()
'Timer***************************************************
Application.ScreenUpdating = False
Dim secs1 As Single
Dim secs2 As Single
secs1 = Timer()

Sheets("Capstudy").Select
Dim cell As Object

' Change to 3 decimal places
For Each cell In Range("Pod")
If IsNumeric(cell) Then
cell.Value = WorksheetFunction.Round(cell.Value, 3) ' SETS TO 3 DECIMAL PLACES
End If
Next cell
Range("A2").Select
Application.CutCopyMode = False

' End of code to be timed
secs2 = Timer()
Worksheets("Capstudy").Range("D5").Value = secs2 - secs1
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also do you have any text cells within the range?
 
Upvote 0
i'm trying to round named range cells to 3 decimal places to ensure files are not to big.
Named range: "Pod", 1435 rows by 48 column's = 68880 cells

The code below takes 35.75 seconds to run.

Question can it be done faster ?

Regards Bernie


VBA Code:
Sub Rounding()
'Timer***************************************************
Application.ScreenUpdating = False
Dim secs1 As Single
Dim secs2 As Single
secs1 = Timer()

Sheets("Capstudy").Select
Dim cell As Object

' Change to 3 decimal places
For Each cell In Range("Pod")
If IsNumeric(cell) Then
cell.Value = WorksheetFunction.Round(cell.Value, 3) ' SETS TO 3 DECIMAL PLACES
End If
Next cell
Range("A2").Select
Application.CutCopyMode = False

' End of code to be timed
secs2 = Timer()
Worksheets("Capstudy").Range("D5").Value = secs2 - secs1
Application.ScreenUpdating = True
End Sub
No text in range, previous macro checked
Excel: Microsoft® Excel® for Microsoft 365 MSO (16.0.14228.20216) 64-bit
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Also do you have any text cells within the range?
Hi Fluff

No text in range, previous macro checked
Excel: Microsoft® Excel® for Microsoft 365 MSO (16.0.14228.20216) 64-bit

Bernie
 
Upvote 0
Ok, how about
VBA Code:
Sub Bernieg()
   With Sheets("Capstudy")
      .Range("Pod").Value = .Evaluate("Round(Pod,3)")
   End With
End Sub
Thanks for updating your profile
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub Bernieg()
   With Sheets("Capstudy")
      .Range("Pod").Value = .Evaluate("Round(Pod,3)")
   End With
End Sub
Thanks for updating your profile
Cheers Jaz

Much appreciated from 35 to 0.07 seconds to process.
Will have to look into how this works.

Bernie
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,816
Members
449,095
Latest member
m_smith_solihull

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