Hello all.
The title basicly says it all. I have a macro which just adds sheets with a desired name. When i wrote the code i looked if it works as intended in debug mode. But as soon as i wanted to run the macro normally it errors out.
the code that i run is as follows:
the code which gets called:
it errors out on
The title basicly says it all. I have a macro which just adds sheets with a desired name. When i wrote the code i looked if it works as intended in debug mode. But as soon as i wanted to run the macro normally it errors out.
the code that i run is as follows:
VBA Code:
Sub killast()
With Worksheets("vorlage").Range("anzahltage2")
Dim kill As Integer
If .Value > 2 Then
sheetname = Sheets(Sheets("Vorlage").Index + 1).Name
kill = MsgBox("Willst du wirklich Das kalkulationsblatt ""K(" & .Value - 1 & ")""löschen?", vbQuestion + vbYesNo + vbDefaultButton1)
If kill = vbYes And .Value > 1 Then
sn = "K(" & .Value - 1 & ")"
Application.DisplayAlerts = False
Worksheets(sn).Unprotect
Sheets(sn).Delete
'Sheets("K(" & .Value - 2 & ")").Activate
Application.DisplayAlerts = True
Worksheets("vorlage").Unprotect
.Value = .Value - 1
Worksheets("vorlage").Protect
Else
Exit Sub
End If
Else
sn = Sheets(Sheets("Vorlage").Index + 1).Name
kill2 = MsgBox("Willst du wirklich die daten aus dem blatt """ & sn & """löschen?", vbQuestion + vbYesNo + vbDefaultButton1)
If kill2 = vbYes Then
Application.DisplayAlerts = False
Sheets(sn).Unprotect
Sheets(sn).Delete
Application.DisplayAlerts = True
Call Copyrenameworksheetss
End If
End If
End With
End Sub
the code which gets called:
VBA Code:
Sub Copyrenameworksheetss()
'Updateby Extendoffice
Dim ws As Worksheet
Set wh = Worksheets(ActiveSheet.Name)
With Worksheets("Vorlage").Range("AnzahlTage2")
ThisWorkbook.Worksheets("Vorlage").Visible = True
Sheets("Vorlage").Copy after:=Sheets(Sheets.Count)
If IsNumeric(.Value) Then
'ActiveSheet.Name = "Tag " & .Value
If Not Sheets.Count - Sheets("Vorlage").Index = .Value Then
Sheets("Vorlage").Unprotect
.Value = Sheets.Count - Sheets("Vorlage").Index - 1
Sheets("Vorlage").Protect
End If
If Sheets.Count - Sheets("Vorlage").Index = .Value + 1 Then
Sheets("Vorlage").Unprotect
.Value = Sheets.Count - Sheets("Vorlage").Index
sn = "K(" & .Value & ")"
Sheets("Vorlage").Protect
End If
sn = "K(" & .Value & ")"
ActiveSheet.Name = "K(" & .Value & ")"
'Sheets("Tag " & .Value).Tab.ColorIndex = 10
Sheets(sn).Tab.ColorIndex = 10
Worksheets("Vorlage").Unprotect
.Value = .Value + 1
Worksheets("Vorlage").Protect
ThisWorkbook.Worksheets("Vorlage").Visible = False
End If
GoTo ciao
End With
ciao:
End Sub
it errors out on
VBA Code:
Worksheets("Vorlage").Unprotect