This code works sometimes and others I get the "code interuption" error. I can continue and it works. And it seems to pick from two different places in the code to stop at on random basis. Since I can discern a pattern I kinda don't know what to do to troubleshoot it. Any advice?
VBA Code:
Sub SaveAsCopy()
'Saves copy of workbook to filename as value of Q1
Dim PathName, FileName As String
FileName = Range("Q1").Value & ".xlsm"
If Len(FileName) > 0 Then
PathName = ThisWorkbook.Path
If Dir(PathName, vbDirectory) = "" Then MkDir PathName
ThisWorkbook.SaveAs PathName & "\" & FileName
Else
Range("q1").Select
MsgBox "File name in P1 is not found", vbExclamation, "Not saved": Exit Sub
End If
Range("h11:h500").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'ActiveWindow.ScrollColumn = 2
'ActiveWindow.ScrollColumn = 1
Application.SendKeys ("{ESC}")
Range("e2").Select '<<<<<<<<<<<this is the most common line highlighted in debugger
Rows("2:7").Select
Range("E2").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False ' <<<<<<<<<<<<<<<<<This is the next most common line.
Range("F8").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Inventory Calculations").Select
Columns("A:s").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub