From d52839d6cb36314ed18416c5d831b2e8b24814de Mon Sep 17 00:00:00 2001 From: kevinowino869 Date: Sun, 2 Mar 2025 14:26:05 +0100 Subject: [PATCH] Update ResetFilters/ResetFilters.bas --- ResetFilters/ResetFilters.bas | 67 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/ResetFilters/ResetFilters.bas b/ResetFilters/ResetFilters.bas index 5378a6e..406d1f8 100644 --- a/ResetFilters/ResetFilters.bas +++ b/ResetFilters/ResetFilters.bas @@ -1,34 +1,33 @@ -Attribute VB_Name = "ResetFilters" - -Sub ResetFilters() - Dim wsData As Worksheet, wsDash As Worksheet - Dim lastRow As Long, headerRow As Long - Dim fullRange As Range - - ' Set references to sheets - Set wsData = ThisWorkbook.Sheets("Datasheet") - Set wsDash = ThisWorkbook.Sheets("Dashboard") - - ' Define last row of data - lastRow = wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row - headerRow = 1 ' Assuming headers are in row 1 - - ' Clear previous results - wsDash.Range("A10:L35").ClearContents - - ' Remove any active filters - If wsData.AutoFilterMode Then wsData.AutoFilterMode = False - - ' Copy all data - Set fullRange = wsData.Range(wsData.Cells(headerRow, 1), wsData.Cells(lastRow, wsData.UsedRange.Columns.Count)) - - ' Copy headers - wsData.Rows(headerRow).Copy Destination:=wsDash.Rows(9) - - ' Copy entire dataset - fullRange.Offset(1, 0).Copy - wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteValues - wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteFormats - Application.CutCopyMode = False -End Sub - + +Sub ResetFilters() + Dim wsData As Worksheet, wsDash As Worksheet + Dim lastRow As Long, headerRow As Long + Dim fullRange As Range + + ' Set references to sheets + Set wsData = ThisWorkbook.Sheets("Datasheet") + Set wsDash = ThisWorkbook.Sheets("Dashboard") + + ' Define last row of data + lastRow = wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row + headerRow = 1 ' Assuming headers are in row 1 + + ' Clear previous results + wsDash.Range("A10:L35").ClearContents + + ' Remove any active filters + If wsData.AutoFilterMode Then wsData.AutoFilterMode = False + + ' Copy all data + Set fullRange = wsData.Range(wsData.Cells(headerRow, 1), wsData.Cells(lastRow, wsData.UsedRange.Columns.Count)) + + ' Copy headers + wsData.Rows(headerRow).Copy Destination:=wsDash.Rows(9) + + ' Copy entire dataset + fullRange.Offset(1, 0).Copy + wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteValues + wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteFormats + Application.CutCopyMode = False +End Sub +