I have the following (previously working) code which converts formulas to their constant values. I attached it to a form button on the spreadsheet. It was working fine, and then decided to break. I click on the button or run the Macro and a box comes up with "Automation error". Excel help describes it as a "Automation error (Error 440)".
I have followed the advice of forums, inserting "On Error Resume Next" statement in various places. I have tried recreating the Macro. I have tried some different versions of the Macro. But have not managed to fix it yet. How do I get rid of this error? Is it something similar to a try catch statement in Java and Python?
Sub RangeOfFormulasToConstants()
'
' Changes a selection of Formulas into their values thus removing the formula.
'
' Keyboard Shortcut: Ctrl+q
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Useful box"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
For Each Rng In WorkRng
Rng.Value = Rng.Text
Next
Application.ScreenUpdating = True
End Sub
I have other Macros which are currently working with the spreadsheet and form buttons. Detailed below.
Sub CopyFormulasNonCalculate()
'
' PasteMacro Macro
'
' Keyboard Shortcut: Ctrl+m
'
On Error Resume Next
Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
On Error GoTo 0
If Not Ret Is Nothing Then
Selection.Copy
Range("C2:F2").Copy Destination:=Ret
Application.CutCopyMode = False
End If
End Sub
Sub CopyFormulasCalculate()
Dim Ret As Range
Dim RangeToCopy As Range
Set RangeToCopy = Range("H3:AF3")
'
' PasteMacro Macro
'
' Keyboard Shortcut: Ctrl+m
'
Set Ret = Application.InputBox(Prompt:="Please select a range where you want to paste", Type:=8)
If Not Ret Is Nothing Then
RangeToCopy.Copy Destination:=Ret
Ret.Resize(1, RangeToCopy.Columns.Count).Calculate
Application.CutCopyMode = False
End If
End Sub