Update ResetFilters/ResetFilters.bas

This commit is contained in:
kevinowino869 2025-03-02 14:26:05 +01:00
parent 25e930145c
commit d52839d6cb

View File

@ -1,34 +1,33 @@
Attribute VB_Name = "ResetFilters"
Sub ResetFilters()
Sub ResetFilters() Dim wsData As Worksheet, wsDash As Worksheet
Dim wsData As Worksheet, wsDash As Worksheet Dim lastRow As Long, headerRow As Long
Dim lastRow As Long, headerRow As Long Dim fullRange As Range
Dim fullRange As Range
' Set references to sheets
' Set references to sheets Set wsData = ThisWorkbook.Sheets("Datasheet")
Set wsData = ThisWorkbook.Sheets("Datasheet") Set wsDash = ThisWorkbook.Sheets("Dashboard")
Set wsDash = ThisWorkbook.Sheets("Dashboard")
' Define last row of data
' Define last row of data lastRow = wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row
lastRow = wsData.Cells(wsData.Rows.Count, 1).End(xlUp).Row headerRow = 1 ' Assuming headers are in row 1
headerRow = 1 ' Assuming headers are in row 1
' Clear previous results
' Clear previous results wsDash.Range("A10:L35").ClearContents
wsDash.Range("A10:L35").ClearContents
' Remove any active filters
' Remove any active filters If wsData.AutoFilterMode Then wsData.AutoFilterMode = False
If wsData.AutoFilterMode Then wsData.AutoFilterMode = False
' Copy all data
' Copy all data Set fullRange = wsData.Range(wsData.Cells(headerRow, 1), wsData.Cells(lastRow, wsData.UsedRange.Columns.Count))
Set fullRange = wsData.Range(wsData.Cells(headerRow, 1), wsData.Cells(lastRow, wsData.UsedRange.Columns.Count))
' Copy headers
' Copy headers wsData.Rows(headerRow).Copy Destination:=wsDash.Rows(9)
wsData.Rows(headerRow).Copy Destination:=wsDash.Rows(9)
' Copy entire dataset
' Copy entire dataset fullRange.Offset(1, 0).Copy
fullRange.Offset(1, 0).Copy wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteValues
wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteValues wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteFormats
wsDash.Cells(10, 1).PasteSpecial Paste:=xlPasteFormats Application.CutCopyMode = False
Application.CutCopyMode = False End Sub
End Sub