I’ve got this macro which does what I need it to do but when used for a file with over 10,000 or so “ =HP “ (macro search criteria), it freezes up computers and takes a very long time to process. I took off screen updating to watch it run and at first it was going quickly cell by cell, then its performance worsened and it went very slowly cell by cell so that to complete 12 cells it would take about 20 seconds.
Does anyone know a way to write this formula in a more efficient manor?
I have some other valuing macro's which run at speeds which could probably only be measured in nano seconds, but it doesn't look cell by cell
Is their a way to rewrite the first marco to make it run as fast as the second?
Does anyone know a way to write this formula in a more efficient manor?
Code:
Sub ValueHPAll()
TxtMsg = "You have selected to value all Hyperion formula's in this workbook. If you wish to proceed please select OK"
y = MsgBox(TxtMsg, vbOKCancel, "Proceeding with valuing Hyperion formula's.")
Application.ScreenUpdating = False 'turn off screen updating
If y = 1 Then
Dim sh As Worksheet, HidShts As New Collection
For Each sh In ActiveWorkbook.Worksheets
If Not sh.Visible Then
HidShts.Add sh
sh.Visible = xlSheetVisible
End If
Next sh
For Each x In Worksheets
Sheets(x.Name).Activate
Range("a1").Select
ActiveCell.SpecialCells(xlLastCell).Select
LastCell = ActiveCell.Address
Range("a1:" & LastCell).Select
For Each z In Selection
If InStr(1, z.FormulaR1C1, "HPLNK") = 0 Then
If InStr(1, z.FormulaR1C1, "HP") > 0 Or InStr(1, z.FormulaR1C1, "hp") > 0 Then
If z.HasFormula Then
z.Copy
z.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
End If
Next z
Range("a1").Select
Next x
Application.ScreenUpdating = True 'refresh the screen
For Each sh In HidShts
sh.Visible = xlSheetHidden
Next sh
Else
MsgBox "You have chosen to cancel this process"
End If
End Sub
I have some other valuing macro's which run at speeds which could probably only be measured in nano seconds, but it doesn't look cell by cell
Code:
Sub ValueAll()
TxtMsg = "You have selected to value all formula's in this workbook. If you wish to proceed please select OK"
y = MsgBox(TxtMsg, vbOKCancel, "Proceeding with valuing all formula's.")
Application.ScreenUpdating = False 'turn off screen updating
If y = 1 Then
Dim sh As Worksheet, HidShts As New Collection
For Each sh In ActiveWorkbook.Worksheets
If Not sh.Visible Then
HidShts.Add sh
sh.Visible = xlSheetVisible
End If
Next sh
Worksheets.Select
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Select
Application.CutCopyMode = False
For Each sh In HidShts
sh.Visible = xlSheetHidden
Next sh
Application.ScreenUpdating = True 'refresh the screen
Else
MsgBox "You have chosen to cancel this process"
End If
End Sub
Is their a way to rewrite the first marco to make it run as fast as the second?