Update ClearReports/ClearReports.bas

This commit is contained in:
kevinowino869 2025-03-02 14:21:48 +01:00
parent 4af67db419
commit b2e084bd10

View File

@ -1,37 +1,35 @@
Attribute VB_Name = "ClearReports"
Sub ClearReportsButton()
Dim ws As Worksheet
Dim wsArr As Variant
Dim i As Integer
' Define sheets to keep
wsArr = Array("Dashboard", "Datasheet", "Code")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Loop backwards to avoid deletion issues
For i = ThisWorkbook.Sheets.Count To 1 Step -1
Set ws = ThisWorkbook.Sheets(i)
If Not IsInArray(ws.Name, wsArr) Then
ws.Delete
End If
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "All county reports have been cleared!", vbInformation
End Sub
' Function to check if sheet name is in the list of sheets to keep
Function IsInArray(val As String, arr As Variant) As Boolean
Dim i As Integer
For i = LBound(arr) To UBound(arr)
If arr(i) = val Then
IsInArray = True
Exit Function
End If
Next i
IsInArray = False
End Function
Sub ClearReportsButton()
Dim ws As Worksheet
Dim wsArr As Variant
Dim i As Integer
' Define sheets to keep
wsArr = Array("Dashboard", "Datasheet", "Code")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
' Loop backwards to avoid deletion issues
For i = ThisWorkbook.Sheets.Count To 1 Step -1
Set ws = ThisWorkbook.Sheets(i)
If Not IsInArray(ws.Name, wsArr) Then
ws.Delete
End If
Next i
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "All county reports have been cleared!", vbInformation
End Sub
' Function to check if sheet name is in the list of sheets to keep
Function IsInArray(val As String, arr As Variant) As Boolean
Dim i As Integer
For i = LBound(arr) To UBound(arr)
If arr(i) = val Then
IsInArray = True
Exit Function
End If
Next i
IsInArray = False
End Function