Code run speed - Move trailing minus sign

rossi789

New Member
Joined
Jul 30, 2015
Messages
31
I came across the below code to fix a trailing minus sign in some data. The workbook is intended to be a template with a series of calculations from the data on 5 other worksheets. Running the code in a separate workbook completes smoothly and within a second or two. However running it in the workbook including calculations takes forever. Could this be because excel is recalculating all formulas for each change that is made?

Is there a change that could be made to fix this?

Code:
Sub Negsignleft()    
    Dim cell As Range
    Dim rng As Range
    ''move minus sign from right to left on entire worksheet
    On Error Resume Next
    Set rng = ActiveSheet.Range("E1:F15000"). _
            SpecialCells(xlCellTypeConstants, xlTextValues)
    On Error GoTo 0
    For Each cell In rng
        If IsNumeric(cell.Value) Then
            cell.Value = CDbl(cell.Value)
        End If
    Next cell
End Sub

Thanks
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This should execute much faster for you...
Code:
Sub Negsignleft()
  Columns("E").TextToColumns TrailingMinusNumbers:=True
  Columns("F").TextToColumns TrailingMinusNumbers:=True
End Sub
 
Upvote 0
For future reference, you can turn calculations off or on very simply
Code:
Application.Calculation = xlCalculationManual
turns it off.

Code:
Application.Calculation = xlCalculationAutomatic
turns it on

There's another rarely used option which sets calculations on for everything except tables, only used when you have large (100K rows+) with chunky calculated columns
Code:
Application.Calculation = xlCalculationSemiautomatic

If you have a workbook that needs to be kept manual (e.g. they have external data connections which refresh every time you do a calculate) you can force a recalculate before a save:-
Code:
Application.CalculateBeforeSave = True
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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