Excel crashes when I run this code can you see why?

Tezzerk

New Member
Joined
Apr 25, 2004
Messages
23
When I run the following code it falls over when it gets towards the end and I try to delete sheets and then a button and drop down list box and then clear some formatting by deleting a range of cells. It fails before the macros are deleted.

Here is the code

Sub SetForSave()
'
' SetForSave Macro
' Macro recorded 15/08/2006 by Terry Kinnard
'
Dim result
' Make all formulae into fixed values
' Site Name
Range("C5").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' Date
Range("C13").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' Address Range
Range("C7:C11").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' Branch Contact
Range("C32").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
' Branch Fax number
Range("F32").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Select Case Range("k13").Value
Case 10
ChDrive ("P")
ChDir ("\10_Service\Clients\Debenhams\Quotes")
Case 20
ChDrive ("P")
ChDir ("\20_Serv\20_admin\LJN\DEBENHAMS")
Case 30
ChDrive ("P")
ChDir ("\10_Service\Clients\Debenhams\Quotes")
Case 40
ChDrive ("P")
ChDir ("\40_Service\Debenhams\Quotes")
End Select

ActiveWorkbook.SaveAs Filename:= _
Range("C15").Value, FileFormat:=xlNormal, _
CreateBackup:=True

' Turn alerts off while we delete sheets
Application.DisplayAlerts = False
' on error goto SetForSaveError

' Remove extra sheets and clear button and coloured area on main sheet.
Sheets("Change Log").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Tables").Select
ActiveWindow.SelectedSheets.Delete

' Remove the drop down list box and the command buttoN
Sheets("DEBENHAMS QUOTATION").Select

ActiveSheet.Shapes("cbSetForSave").Select
Selection.Delete
ActiveSheet.Shapes("ddSiteList").Select
Selection.Delete

' Turn alerts back on again after deleting sheets
Application.DisplayAlerts = True

Range("H6:R11").Select
Selection.Delete Shift:=xlToLeft

' Now get rid of the macros
Call RemoveAllMacros(ActiveWorkbook)

' Call TurnOnScreenUpdates
Exit Sub

SetForSaveError:
' Process error so that we see the error code and error message associated with the error
result = MsgBox("Error in procedure SetForSave Error code = " & Err.Number & " Error Description = " & Err.Description & " Error Source = " & Err.Source, vbOKOnly, "Trapped Error")

Resume Next

End Sub


Thanks for any help you can give. We are still using Excel 2000. I've run the same code on Excel 2002 and it still crashes.

Regards

Terry
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Asala42

Well-known Member
Joined
Feb 26, 2002
Messages
2,318
I'd go back in and run the code line by line by clicking somewhere in Sub and hitting F8 repeatedly. That should help narrow down which line is causing the problem at least.
 

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
I think this could happen:

You have deleted all the sheets.
You are calling the activesheet.

Don't know if that is what's happening, but it might be. Excel works in strange ways sometimes.
 

Tezzerk

New Member
Joined
Apr 25, 2004
Messages
23
I only delete two of three sheets

The code deletes the change log and the sheet containing tables but the main sheet is left. I then try to invoke the sheet and I think it is when I'm trying to clear the block of cells that Excel crashes but I've not been able to trap it or step through successfully.

Regards

Terry
 

Watch MrExcel Video

Forum statistics

Threads
1,133,654
Messages
5,660,140
Members
418,553
Latest member
judithcatherine

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
Top