I have a macro that runs from the VBA editor but crashes if run from a button on a worksheet. It is an out of range error referring to a userform that is unloaded at the start of the macro. I unloaded the userform and made the workbook active at the beginning of the macro without success. The error occurrs in the worksheet calculate event routine.
Any insight is helpful. Let me know if additional info is needed.
The error occurs here Private Sub Worksheet_Calculate()
Any insight is helpful. Let me know if additional info is needed.
VBA Code:
Sub PFF()
Windows("Single Game.xlsm").Activate
Sheets("single").Select
Dim path As String
path = ThisWorkbook.path
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Unload UserForm9
Workbooks.Open Filename:=(path & "\exports\single dfs.xlsx")
ActiveWorkbook.Save
ActiveWindow.Close
PFFNewestFile
ActiveSheet.Name = "1"
ActiveWorkbook.SaveAs Filename:=path & "\Exports\Single DFS.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
PFFImportPic
ActiveWorkbook.Save
ActiveWindow.Close
Application.ScreenUpdating = True
End Sub
The error occurs here Private Sub Worksheet_Calculate()
VBA Code:
If Sheets("SINGLE").Range("Q134").Value > 0 Then UserForm9.Frame10.BackColor = &HC0FFC0
If Sheets("SINGLE").Range("Q134").Value = "" Then UserForm9.Frame10.BackColor = &HC0FFFF