So my problem is that everything works perfectly fine even when i click the buttons, but the second time i want to click them it gives me an error and the whole excel document is almost like in debug mode even after i clicked stop.
I am able to type on other excel sheets however no cursor appears nor the green box around cells when you click them.
This code copies either one or all of the sheets from workbook, opens a new workbook and pastes the sheet there all while being protected. Again it has work in the past but now it only works the first time i click it and none after that and i cant seem to figure out why.
the error on the second try is "method copy of object range failed". But if it worked the fist time why not the second??
thank you
EDIT: also when you exit out of excel after i get this error it says "excel stopped working and is checking for a solution"
Sub copy_first_sheet()
Sheet20.Unprotect ""
Dim newbook As String
Dim GetBook As String
GetBook = ActiveWorkbook.Name
Call CopyWorksheetValues
Call Clear_Buttons
Call DeleteallCharts
ActiveSheet.Range("a59:i180").Clear
ActiveSheet.Range("67:68").Locked = True
Rows("67:180").EntireRow.Hidden = True
ActiveWindow.DisplayGridlines = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With
newbook = ActiveWorkbook.Name
ActiveSheet.Protect ""
Workbooks(GetBook).Activate
Sheet20.Protect ""
Workbooks(newbook).Activate
End Sub
Sub copy_all_sheet()
Sheet20.Unprotect ""
Dim newbook As String
Dim GetBook As String
GetBook = ActiveWorkbook.Name
Call CopyWorksheetValues
Call Clear_Buttons
ActiveSheet.Range("67:68").Locked = True
ActiveWindow.DisplayGridlines = False
newbook = ActiveWorkbook.Name
ActiveSheet.Protect ""
Workbooks(GetBook).Activate
Sheet20.Protect ""
Workbooks(newbook).Activate
End Sub
Sub Clear_Buttons()
Dim i As Integer
ActiveSheet.Buttons.delete
End Sub
Sub CopyWorksheetValues()
ThisWorkbook.Worksheets("comparison").Copy
Cells.Copy
Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
Sub DeleteallCharts()
Dim chtObj As ChartObject
For Each chtObj In ActiveSheet.ChartObjects
chtObj.delete
Next
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If pic.Name <> "" Then
pic.delete
End If
Next pic
End Sub
Bookmarks