D
DynamiteSkippy
I am trying to loop through all charts in a workbook and delete all but 2
charts specified by a variable name.
Below is my entire code... I am specifically working on the second for loop.
THe problem I am trying to resolve is that it deletes all charts irregardless
of name.
Sub DelSheets()
Dim i As Integer
Dim Wks
Dim Cht
Dim NoGo1, NoGo2 As String
PraSpecialty = "CARDIO"
For Each Wks In ThisWorkbook.Worksheets
'MsgBox prompt:="Wks" & " " & Wks.Name
If Left(Wks.Name, 5) = "Sheet" Then
Application.DisplayAlerts = False
Wks.Delete
Application.DisplayAlerts = True
Else
'MsgBox "Sorry, you cannot delete this sheet"
End If
Next Wks
For Each Cht In ThisWorkbook.Charts
NoGo1 = PraSpecialty & "_ChartList"
NoGo2 = PraSpecialty & "_Chart"
If Cht.Name <> NoGo1 Or Cht.Name <> NoGo2 Then
Application.DisplayAlerts = False
'Cht.Delete
MsgBox "DELETE->" & Cht.Name
Application.DisplayAlerts = True
Else
MsgBox Cht.Name
'MsgBox "Sorry, you cannot delete this chart"
End If
Next Cht
MsgBox "Wait a tick... Is this working?"
End Sub
charts specified by a variable name.
Below is my entire code... I am specifically working on the second for loop.
THe problem I am trying to resolve is that it deletes all charts irregardless
of name.
Sub DelSheets()
Dim i As Integer
Dim Wks
Dim Cht
Dim NoGo1, NoGo2 As String
PraSpecialty = "CARDIO"
For Each Wks In ThisWorkbook.Worksheets
'MsgBox prompt:="Wks" & " " & Wks.Name
If Left(Wks.Name, 5) = "Sheet" Then
Application.DisplayAlerts = False
Wks.Delete
Application.DisplayAlerts = True
Else
'MsgBox "Sorry, you cannot delete this sheet"
End If
Next Wks
For Each Cht In ThisWorkbook.Charts
NoGo1 = PraSpecialty & "_ChartList"
NoGo2 = PraSpecialty & "_Chart"
If Cht.Name <> NoGo1 Or Cht.Name <> NoGo2 Then
Application.DisplayAlerts = False
'Cht.Delete
MsgBox "DELETE->" & Cht.Name
Application.DisplayAlerts = True
Else
MsgBox Cht.Name
'MsgBox "Sorry, you cannot delete this chart"
End If
Next Cht
MsgBox "Wait a tick... Is this working?"
End Sub