PC Review


Reply
Thread Tools Rate Thread

code to replace advanced auto filter

 
 
Belinda7237
Guest
Posts: n/a
 
      12th Jun 2008
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.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      12th Jun 2008
try this. When you open a new workbook the focus changes to the new book.

with thisworkbook.Sheets("East Master Repository")
.Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=thisworkbook.Sheets( _
"Criteria for market groupings").Range("N2:N7"), Unique:=False
set newbk = workbooks.add
.Cells.Copy destination:=newbk.sheets(1).cells

end with

"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.

 
Reply With Quote
 
Belinda7237
Guest
Posts: n/a
 
      12th Jun 2008
I am getting a syntax error i blieve on .Rows

"Joel" wrote:

> try this. When you open a new workbook the focus changes to the new book.
>
> with thisworkbook.Sheets("East Master Repository")
> .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> CriteriaRange:=thisworkbook.Sheets( _
> "Criteria for market groupings").Range("N2:N7"), Unique:=False
> set newbk = workbooks.add
> .Cells.Copy destination:=newbk.sheets(1).cells
>
> end with
>
> "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.

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      12th Jun 2008
The line was too long and wrapped. I added a continuation character at the
end of the line which was too long.

with thisworkbook.Sheets("East Master Repository")
.Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=thisworkbook.Sheets( _
"Criteria for market groupings").Range("N2:N7"), Unique:=False
set newbk = workbooks.add
.Cells.Copy destination:=newbk.sheets(1).cells

end with



"Belinda7237" wrote:

> I am getting a syntax error i blieve on .Rows
>
> "Joel" wrote:
>
> > try this. When you open a new workbook the focus changes to the new book.
> >
> > with thisworkbook.Sheets("East Master Repository")
> > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> > CriteriaRange:=thisworkbook.Sheets( _
> > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > set newbk = workbooks.add
> > .Cells.Copy destination:=newbk.sheets(1).cells
> >
> > end with
> >
> > "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.

 
Reply With Quote
 
Belinda7237
Guest
Posts: n/a
 
      14th Jun 2008
Its actually still producing a compile error on the last line indicated its
an invaoid or unqualified reference at .cells?

thoughts?

"Joel" wrote:

> The line was too long and wrapped. I added a continuation character at the
> end of the line which was too long.
>
> with thisworkbook.Sheets("East Master Repository")
> .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
> CriteriaRange:=thisworkbook.Sheets( _
> "Criteria for market groupings").Range("N2:N7"), Unique:=False
> set newbk = workbooks.add
> .Cells.Copy destination:=newbk.sheets(1).cells
>
> end with
>
>
>
> "Belinda7237" wrote:
>
> > I am getting a syntax error i blieve on .Rows
> >
> > "Joel" wrote:
> >
> > > try this. When you open a new workbook the focus changes to the new book.
> > >
> > > with thisworkbook.Sheets("East Master Repository")
> > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> > > CriteriaRange:=thisworkbook.Sheets( _
> > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > set newbk = workbooks.add
> > > .Cells.Copy destination:=newbk.sheets(1).cells
> > >
> > > end with
> > >
> > > "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.

 
Reply With Quote
 
Debra Dalgleish
Guest
Posts: n/a
 
      14th Jun 2008
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

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      14th Jun 2008
I don't understand why you are getting this error. Running the new code
below should always work (I removed the filter lines) as long as you have the
worksheet "East MasterRepository". the code creates a new workbook which
should always work. the copy line copies every cell and puts it in the new
workbook in sheet 1. You can't creater a workbook without one worksheet so
this shouldn't fail either. I don't have an answer unless you didn't type
the code correctly.

With ThisWorkbook.Sheets("East Master Repository")

Set newbk = Workbooks.Add
.Cells.Copy Destination:=newbk.Sheets(1).Cells

End With


"Belinda7237" wrote:

> Its actually still producing a compile error on the last line indicated its
> an invaoid or unqualified reference at .cells?
>
> thoughts?
>
> "Joel" wrote:
>
> > The line was too long and wrapped. I added a continuation character at the
> > end of the line which was too long.
> >
> > with thisworkbook.Sheets("East Master Repository")
> > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
> > CriteriaRange:=thisworkbook.Sheets( _
> > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > set newbk = workbooks.add
> > .Cells.Copy destination:=newbk.sheets(1).cells
> >
> > end with
> >
> >
> >
> > "Belinda7237" wrote:
> >
> > > I am getting a syntax error i blieve on .Rows
> > >
> > > "Joel" wrote:
> > >
> > > > try this. When you open a new workbook the focus changes to the new book.
> > > >
> > > > with thisworkbook.Sheets("East Master Repository")
> > > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> > > > CriteriaRange:=thisworkbook.Sheets( _
> > > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > > set newbk = workbooks.add
> > > > .Cells.Copy destination:=newbk.sheets(1).cells
> > > >
> > > > end with
> > > >
> > > > "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.

 
Reply With Quote
 
Belinda7237
Guest
Posts: n/a
 
      14th Jun 2008
Using this, it does create a new workbook, however it errors when it gets to
Advanced filter due to having a shared workbook.

"Joel" wrote:

> I don't understand why you are getting this error. Running the new code
> below should always work (I removed the filter lines) as long as you have the
> worksheet "East MasterRepository". the code creates a new workbook which
> should always work. the copy line copies every cell and puts it in the new
> workbook in sheet 1. You can't creater a workbook without one worksheet so
> this shouldn't fail either. I don't have an answer unless you didn't type
> the code correctly.
>
> With ThisWorkbook.Sheets("East Master Repository")
>
> Set newbk = Workbooks.Add
> .Cells.Copy Destination:=newbk.Sheets(1).Cells
>
> End With
>
>
> "Belinda7237" wrote:
>
> > Its actually still producing a compile error on the last line indicated its
> > an invaoid or unqualified reference at .cells?
> >
> > thoughts?
> >
> > "Joel" wrote:
> >
> > > The line was too long and wrapped. I added a continuation character at the
> > > end of the line which was too long.
> > >
> > > with thisworkbook.Sheets("East Master Repository")
> > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
> > > CriteriaRange:=thisworkbook.Sheets( _
> > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > set newbk = workbooks.add
> > > .Cells.Copy destination:=newbk.sheets(1).cells
> > >
> > > end with
> > >
> > >
> > >
> > > "Belinda7237" wrote:
> > >
> > > > I am getting a syntax error i blieve on .Rows
> > > >
> > > > "Joel" wrote:
> > > >
> > > > > try this. When you open a new workbook the focus changes to the new book.
> > > > >
> > > > > with thisworkbook.Sheets("East Master Repository")
> > > > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> > > > > CriteriaRange:=thisworkbook.Sheets( _
> > > > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > > > set newbk = workbooks.add
> > > > > .Cells.Copy destination:=newbk.sheets(1).cells
> > > > >
> > > > > end with
> > > > >
> > > > > "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.

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      15th Jun 2008
I not sure why th e code would fail because of a shared workbook. I suspect
the code is failing because the line is wrapping. I looked again at the way
the code got posted and noticed it look like the Copy line is on two lines
instead of one below I added a line continuation character at the end of the
line to prevent this error

With ThisWorkbook.Sheets("East Master Repository")

Set newbk = Workbooks.Add
.Cells.Copy _
Destination:=newbk.Sheets(1).Cells
End With


"Belinda7237" wrote:

> Using this, it does create a new workbook, however it errors when it gets to
> Advanced filter due to having a shared workbook.
>
> "Joel" wrote:
>
> > I don't understand why you are getting this error. Running the new code
> > below should always work (I removed the filter lines) as long as you have the
> > worksheet "East MasterRepository". the code creates a new workbook which
> > should always work. the copy line copies every cell and puts it in the new
> > workbook in sheet 1. You can't creater a workbook without one worksheet so
> > this shouldn't fail either. I don't have an answer unless you didn't type
> > the code correctly.
> >
> > With ThisWorkbook.Sheets("East Master Repository")
> >
> > Set newbk = Workbooks.Add
> > .Cells.Copy Destination:=newbk.Sheets(1).Cells
> >
> > End With
> >
> >
> > "Belinda7237" wrote:
> >
> > > Its actually still producing a compile error on the last line indicated its
> > > an invaoid or unqualified reference at .cells?
> > >
> > > thoughts?
> > >
> > > "Joel" wrote:
> > >
> > > > The line was too long and wrapped. I added a continuation character at the
> > > > end of the line which was too long.
> > > >
> > > > with thisworkbook.Sheets("East Master Repository")
> > > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
> > > > CriteriaRange:=thisworkbook.Sheets( _
> > > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > > set newbk = workbooks.add
> > > > .Cells.Copy destination:=newbk.sheets(1).cells
> > > >
> > > > end with
> > > >
> > > >
> > > >
> > > > "Belinda7237" wrote:
> > > >
> > > > > I am getting a syntax error i blieve on .Rows
> > > > >
> > > > > "Joel" wrote:
> > > > >
> > > > > > try this. When you open a new workbook the focus changes to the new book.
> > > > > >
> > > > > > with thisworkbook.Sheets("East Master Repository")
> > > > > > .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
> > > > > > CriteriaRange:=thisworkbook.Sheets( _
> > > > > > "Criteria for market groupings").Range("N2:N7"), Unique:=False
> > > > > > set newbk = workbooks.add
> > > > > > .Cells.Copy destination:=newbk.sheets(1).cells
> > > > > >
> > > > > > end with
> > > > > >
> > > > > > "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.

 
Reply With Quote
 
Debra Dalgleish
Guest
Posts: n/a
 
      15th Jun 2008
Have you tried your code in a shared workbook? Advanced filter is one of
many features that aren't permitted.

You can manually run an advanced filter on the data, by starting in a
different workbook, but the AdvancedFilter code will create an error.

In my response yesterday, I suggested using an AutoFilter instead.

Joel wrote:
> I not sure why th e code would fail because of a shared workbook. I suspect
> the code is failing because the line is wrapping. I looked again at the way
> the code got posted and noticed it look like the Copy line is on two lines
> instead of one below I added a line continuation character at the end of the
> line to prevent this error
>
> With ThisWorkbook.Sheets("East Master Repository")
>
> Set newbk = Workbooks.Add
> .Cells.Copy _
> Destination:=newbk.Sheets(1).Cells
> End With
>
>
> "Belinda7237" wrote:
>
>
>>Using this, it does create a new workbook, however it errors when it gets to
>>Advanced filter due to having a shared workbook.
>>
>>"Joel" wrote:
>>
>>
>>>I don't understand why you are getting this error. Running the new code
>>>below should always work (I removed the filter lines) as long as you have the
>>>worksheet "East MasterRepository". the code creates a new workbook which
>>>should always work. the copy line copies every cell and puts it in the new
>>>workbook in sheet 1. You can't creater a workbook without one worksheet so
>>>this shouldn't fail either. I don't have an answer unless you didn't type
>>>the code correctly.
>>>
>>>With ThisWorkbook.Sheets("East Master Repository")
>>>
>>> Set newbk = Workbooks.Add
>>> .Cells.Copy Destination:=newbk.Sheets(1).Cells
>>>
>>>End With
>>>
>>>
>>>"Belinda7237" wrote:
>>>
>>>
>>>>Its actually still producing a compile error on the last line indicated its
>>>>an invaoid or unqualified reference at .cells?
>>>>
>>>>thoughts?
>>>>
>>>>"Joel" wrote:
>>>>
>>>>
>>>>>The line was too long and wrapped. I added a continuation character at the
>>>>>end of the line which was too long.
>>>>>
>>>>>with thisworkbook.Sheets("East Master Repository")
>>>>> .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace, _
>>>>> CriteriaRange:=thisworkbook.Sheets( _
>>>>> "Criteria for market groupings").Range("N2:N7"), Unique:=False
>>>>> set newbk = workbooks.add
>>>>> .Cells.Copy destination:=newbk.sheets(1).cells
>>>>>
>>>>>end with
>>>>>
>>>>>
>>>>>
>>>>>"Belinda7237" wrote:
>>>>>
>>>>>
>>>>>>I am getting a syntax error i blieve on .Rows
>>>>>>
>>>>>>"Joel" wrote:
>>>>>>
>>>>>>
>>>>>>>try this. When you open a new workbook the focus changes to the new book.
>>>>>>>
>>>>>>>with thisworkbook.Sheets("East Master Repository")
>>>>>>> .Rows("1:1").AdvancedFilter Action:=xlFilterInPlace,
>>>>>>>CriteriaRange:=thisworkbook.Sheets( _
>>>>>>> "Criteria for market groupings").Range("N2:N7"), Unique:=False
>>>>>>> set newbk = workbooks.add
>>>>>>> .Cells.Copy destination:=newbk.sheets(1).cells
>>>>>>>
>>>>>>>end with
>>>>>>>
>>>>>>>"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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unique Filter Code / Advanced Filter Fester Microsoft Excel Programming 1 30th Oct 2008 05:37 PM
Unique Filter Code / Advanced Filter Fester Microsoft Excel Discussion 1 30th Oct 2008 05:37 PM
Code to replace Advanced Filter RobN Microsoft Excel Misc 4 14th Jun 2007 12:31 PM
Advanced Filter + auto filter Robert Microsoft Excel Worksheet Functions 1 25th Mar 2004 08:18 AM
Auto Filter vs Advanced robeves Microsoft Excel Worksheet Functions 1 26th Nov 2003 12:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:20 AM.