Sub FilteredDataSelection()
Dim wsProducts As Worksheet
Dim wsProductsCopied As Worksheet
Dim WsPriceList As Worksheet
Dim lngLastrow As Long
Dim strCategory As String
Dim i As Integer
Dim rngCategories As Range
Dim rng As Range
Dim intRow As Integer
Dim LastRow As Long, erow As Long
Dim c As Range
Dim d As Range
'ActiveWorkbook.Save
Call subDeleteWorksheet("ProductsCopied")
Call subDeleteWorksheet("Price List")
Sheets.Add.Name = "ProductsCopied"
' Create Price List sheet.
Worksheets.Add After:=Worksheets("ProductsCopied")
ActiveSheet.Name = "Price List"
Set WsPriceList = Worksheets("Price List")
Set wsProductsCopied = Worksheets("ProductsCopied")
Set wsProducts = ThisWorkbook.Worksheets("Products")
Sheets("Products").Activate
'Clear any existing filters
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
'1. Apply Filter
ActiveSheet.Range("A1:ADU5000").AutoFilter Field:=11, Criteria1:="=Play > Essentials*"
'2. Copy Rows minus the header
Application.DisplayAlerts = False
wsProducts.AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy 'copy the AF first
Set rng = wsProducts.UsedRange.Offset(0, 1)
Set rng = rng.Resize(rng.Rows.Count)
rng.Copy
'3. The Sheet & Where you want to paste the filtered data precisely into Sheet x (Sheet 8 in my example)
Sheets("ProductsCopied").Activate
lr = ThisWorkbook.Worksheets("ProductsCopied").Cells(1, 1).SpecialCells(xlCellTypeLastCell).Row + 1
Range("A" & lr).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Call PlayEssentials
Application.DisplayAlerts = True
'4. Clear Filter from original sheet
On Error Resume Next
wsProducts.ShowAllData
On Error GoTo 0
Sheets("Products").Activate
ActiveSheet.Range("A1:ADU5000").AutoFilter Field:=11, Criteria1:="=*Swings,*" ' im filtering by anything in col 24 that contains "P24128"
wsProducts.AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy 'copy the AF first
Set rng = wsProducts.UsedRange.Offset(0, 1)
Set rng = rng.Resize(rng.Rows.Count)
rng.Copy
'3. The Sheet & Where you want to paste the filtered data precisely into Sheet x (Sheet 8 in my example)
Sheets("ProductsCopied").Activate
lr = ThisWorkbook.Worksheets("ProductsCopied").Cells(1, 1).SpecialCells(xlCellTypeLastCell).Row + 3
Range("A" & lr).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Products").Activate
ActiveSheet.Range("A1:ADU5000").AutoFilter Field:=11, Criteria1:="=*Springs & Rockers,*" ' im filtering by anything in col 24 that contains "P24128"
'2. Copy Rows minus the header
Application.DisplayAlerts = False
wsProducts.AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy 'copy the AF first
Set rng = wsProducts.UsedRange.Offset(0, 1)
Set rng = rng.Resize(rng.Rows.Count)
rng.Copy
'3. The Sheet & Where you want to paste the filtered data precisely into Sheet x (Sheet 8 in my example)
Sheets("ProductsCopied").Activate
lr = ThisWorkbook.Worksheets("ProductsCopied").Cells(1, 1).SpecialCells(xlCellTypeLastCell).Row + 3
Range("A" & lr).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Call Freestanding_Swings
Application.DisplayAlerts = True
Sheets("Products").Activate
If wsProducts.AutoFilterMode Then
ActiveSheet.AutoFilterMode = False
End If
On Error Resume Next
ActiveSheet.ShowAllData
On Error GoTo 0
'Will delete worksheet when macro is correct
subDeleteWorksheet ("Price List")
Sheets("ProductsCopied").Activate
ActiveSheet.Name = "Price List"
'WsPriceList.Cells.EntireColumn.AutoFit
Call subDeleteColumn(WsPriceList, "Mark Up%")
Call subDeleteColumn(WsPriceList, "ALP Price")
Call subDeleteColumn(WsPriceList, "SKU and Name Match")
Call subDeleteColumn(WsPriceList, "Short Descrip H2")
Call subDeleteColumn(WsPriceList, "Tags AB2")
Call subDeleteColumn(WsPriceList, "JPG AD2")
Call subDeleteColumn(WsPriceList, "DWG BD2")
Call subDeleteColumn(WsPriceList, "PDF BH2")
Call subDeleteColumn(WsPriceList, "Tech PDF BX2")
Call subDeleteColumn(WsPriceList, "Focus DE2")
Call subDeleteColumn(WsPriceList, "CategoriesAA2")
ActiveSheet.Columns("A:J").AutoFit
Range("A:F").Font.Size = 9
Range("A:F").Font.Color = vbBlack
Range("A:F").Font.Name = "Calibri Light"
Range("D:D").HorizontalAlignment = xlRight
Range("D:D").NumberFormat = "$#,##0.00"
Range("A1").Select
'Range("A2:F2").Font.Size = 12
'Range("A2:F2").Font.Bold = True
'WsPricelist.Columns(1).ClearContents
ActiveWorkbook.Save
End Sub
Private Sub subDeleteWorksheet(strWorksheet As String)
Application.DisplayAlerts = False
On Error Resume Next
Worksheets(strWorksheet).Delete
On Error GoTo 0
Application.DisplayAlerts = True
End Sub
Private Sub subDeleteColumn(ws As Worksheet, strHeader As String)
Dim rngFound As Range
Set rngFound = Worksheets("Price list").Rows(2).Find(strHeader, LookIn:=xlValues)
If Not rngFound Is Nothing Then
rngFound.EntireColumn.Delete
End If
End Sub