View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Debra Dalgleish Debra Dalgleish is offline
external usenet poster
 
Posts: 2,979
Default code to replace advanced auto filter

You could add a column to your table, to check if the item is in your
criteria range. For example, in cell F2:
=COUNTIF($N$2:$N$7,A2)0

Then, use an autofilter to find the rows that have a TRUE in column F,
and copy the results to a new workbook:

'=============================
Sub ExportMyData()
'copy data and headings from filtered table
'
Dim wb As Workbook
Dim wbNew As Workbook
Dim rng As Range
Dim ws1 As Worksheet
Dim ws2 As Worksheet

Set wbNew = Workbooks.Add
Set wb = ThisWorkbook
Set ws1 = wb.Worksheets("East Master Repository")
Set ws2 = wbNew.Worksheets(1)

With ws1
If .FilterMode Then
.ShowAllData
End If
.Range("A1").AutoFilter Field:=6, Criteria1:="TRUE"
End With

On Error Resume Next
Set rng = ws1.AutoFilter.Range
On Error GoTo 0
If rng Is Nothing Then
MsgBox "No data to copy"
Else
rng.Copy Destination:=ws2.Range("A1")
End If

End Sub

'=============================

Belinda7237 wrote:
Is there code that will replace using advanced autofilter in a shared
workbook? currently when i turn my workbook on to shared, the advanced
filters embedded do not work.

Currently I am using:

Sheets("East Master Repository").Select
Rows("1:1").Select
Cells.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Sheets( _
"Criteria for market groupings").Range("N2:N7"), Unique:=False
Cells.Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste

Where my filter criteria is in cells N2 thru N7.



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html