Afternoon,
Self taught user here (I still search web for most answers).
Hiker95 - I have tried your code and I understand the theory behind the loop code:
'HIKER95 original code
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Data" Then
'***** the rest of your macro code goes here *****
End If
Next ws
End Sub
But my code is using a reference to a ListObject (who's name I will NOT know because another macro creates all my sheets and the ListObject tables are auto named and the number of sheets will vary month on month). Apologies if this is not the correct place to put the question.
When I write my code WITHOUT the loop and run it on a sheet then manually selected the next page and run it, it works fine, but when I run your code with mine I get a Run-time Error '1004' AutoFilter method of Range class failed. This is probably down to the
Can you assist? Thanks in advance
My code is:
Private Sub p3DataExtract()
‘Adapted from: hiker95, 10/29/2013
'
http://www.mrexcel.com/forum/excel-questions/735788-run-macro-all-worksheets-except-one.html
' Object is to search data on each persons sheet in the Recipient column and only show their data, by deleting all the other rows off. Master and Names sheets are not to be checked.
Dim ws As Worksheet
'Loop through all sheets and run this code
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Master" And ws.Name <> "Names" Then
With ws
' Hard paste result of formula in cell A1
Range("A1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
' Filter for rows not showing whatever is in Cell A1 and then delete these. Then remove auto filter to leave me relevant data
' For the benefit of this post - the A1 cell is looking for the TAB name, The tab name is based on a list of unique names created from column 7 in the Master sheet, so it will always find 1 row of data minimum
ActiveSheet.ListObjects(1).Range.AutoFilter Field:=7, Criteria1:="<>" & Range("A1").Value, Operator:=xlAnd 'THIS IS WHERE I GET THE ERROR
Rows("3:" & Rows.Count).EntireRow.Delete ' first row of data (row A is NOT part of the ListObject Table) and then delete these
ActiveSheet.ListObjects(1).Range.AutoFilter Field:=7 ' remove the autofilter from column 7 of the data range
End With
End If
Next ws
End Sub