From f134a92a84a9501a7965606911d93e67a5fe8bfd Mon Sep 17 00:00:00 2001 From: nestict Date: Thu, 27 Feb 2025 19:38:36 +0100 Subject: [PATCH] Upload files to "ClearReports" --- ClearReports/ClearReports.bas | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ClearReports/ClearReports.bas diff --git a/ClearReports/ClearReports.bas b/ClearReports/ClearReports.bas new file mode 100644 index 0000000..5fd635c --- /dev/null +++ b/ClearReports/ClearReports.bas @@ -0,0 +1,37 @@ +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 +