PC Review


Reply
Thread Tools Rate Thread

Autofilter on non-active sheet

 
 
=?Utf-8?B?dGlnZ2Vy?=
Guest
Posts: n/a
 
      5th Nov 2007
HI there,

I'm trying to apply an autofilter to each sheet in my workbook to copy data
to a summary sheet based on criteria.

I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'

Can anyone help?

For Each sh In ThisWorkbook.Worksheets
If sh.Name <> DestSh.Name Then
sh.AutoFilterMode = False

sh.Range("Status").AutoFilter , "Open"

Last = LastRow(DestSh)
shLast = LastRow(sh)

'Copy range and paste into Summary as values
With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

'Copy sheet name to Summary column A
DestSh.Cells(Last + 1, "A").Value = sh.Name
End If
Next

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?YnJvcm8xODM=?=
Guest
Posts: n/a
 
      5th Nov 2007
hi Tigger,

I think you may be missing some important syntax from this line try changing
it to reflect the following which I have copied from Excel 2003 Help files
for "Autofilter Method & "Autofilter Object" respectively:

Syntax = expression.AutoFilter(Field, Criteria1, Operator, Criteria2,
VisibleDropDown)
example = w.Range("A1").AutoFilter field:=1, Criteria1:="S"

hth
Rob

__________________
Rob Brockett
NZ
Always learning & the best way to learn is to experience...

"tigger" wrote:

> HI there,
>
> I'm trying to apply an autofilter to each sheet in my workbook to copy data
> to a summary sheet based on criteria.
>
> I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'
>
> Can anyone help?
>
> For Each sh In ThisWorkbook.Worksheets
> If sh.Name <> DestSh.Name Then
> sh.AutoFilterMode = False
>
> sh.Range("Status").AutoFilter , "Open"
>
> Last = LastRow(DestSh)
> shLast = LastRow(sh)
>
> 'Copy range and paste into Summary as values
> With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> .Columns.Count).Value = .Value
> End With
>
> 'Copy sheet name to Summary column A
> DestSh.Cells(Last + 1, "A").Value = sh.Name
> End If
> Next
>
> Thanks

 
Reply With Quote
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      5th Nov 2007
On Nov 5, 9:04 am, tigger <tig...@discussions.microsoft.com> wrote:
> HI there,
>
> I'm trying to apply an autofilter to each sheet in my workbook to copy data
> to a summary sheet based on criteria.
>
> I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'
>
> Can anyone help?
>
> For Each sh In ThisWorkbook.Worksheets
> If sh.Name <> DestSh.Name Then
> sh.AutoFilterMode = False
>
> sh.Range("Status").AutoFilter , "Open"
>
> Last = LastRow(DestSh)
> shLast = LastRow(sh)
>
> 'Copy range and paste into Summary as values
> With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> .Columns.Count).Value = .Value
> End With
>
> 'Copy sheet name to Summary column A
> DestSh.Cells(Last + 1, "A").Value = sh.Name
> End If
> Next
>
> Thanks


Hi
Try this
sh.Range("Status").AutoFilter Field:=1, Criteria1:="Open"

Help says Field is optional, but I got an error if I didn't specify
it.

regards
Paul

 
Reply With Quote
 
=?Utf-8?B?dGlnZ2Vy?=
Guest
Posts: n/a
 
      5th Nov 2007
Thanks guys - worked perfectly!

The other thing I want to do is copy the visible cells in a selected range -
code below.

Any ideas where I should put .SpecialCells(xlCellTypeVisible)?

Thanks

For Each sh In ThisWorkbook.Worksheets
If sh.Name <> DestSh.Name Then
sh.AutoFilterMode = False

sh.Range("A1").AutoFilter Field:=7, Criteria1:="Open"

Last = LastRow(DestSh)
shLast = LastRow(sh)

'Copy range and paste into Summary as values
With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
.Columns.Count).Value = .Value
End With

'Copy sheet name to Summary column A
DestSh.Cells(Last + 1, "A").Value = sh.Name
End If
Next

"(E-Mail Removed)" wrote:

> On Nov 5, 9:04 am, tigger <tig...@discussions.microsoft.com> wrote:
> > HI there,
> >
> > I'm trying to apply an autofilter to each sheet in my workbook to copy data
> > to a summary sheet based on criteria.
> >
> > I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'
> >
> > Can anyone help?
> >
> > For Each sh In ThisWorkbook.Worksheets
> > If sh.Name <> DestSh.Name Then
> > sh.AutoFilterMode = False
> >
> > sh.Range("Status").AutoFilter , "Open"
> >
> > Last = LastRow(DestSh)
> > shLast = LastRow(sh)
> >
> > 'Copy range and paste into Summary as values
> > With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> > DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> > .Columns.Count).Value = .Value
> > End With
> >
> > 'Copy sheet name to Summary column A
> > DestSh.Cells(Last + 1, "A").Value = sh.Name
> > End If
> > Next
> >
> > Thanks

>
> Hi
> Try this
> sh.Range("Status").AutoFilter Field:=1, Criteria1:="Open"
>
> Help says Field is optional, but I got an error if I didn't specify
> it.
>
> regards
> Paul
>
>

 
Reply With Quote
 
=?Utf-8?B?YnJvcm8xODM=?=
Guest
Posts: n/a
 
      5th Nov 2007
Thanks for the feedback :-)

Does this work for you?

For Each sh In ThisWorkbook.Worksheets
With sh
If .Name <> DestSh.Name Then
.AutoFilterMode = False

.Range("A1").AutoFilter Field:=7, Criteria1:="Open"

Last = LastRow(DestSh)
shLast = LastRow(sh)

'Copy range and paste into Summary as values
With .Range("D2:H2", .Cells(.Rows.Count,
"D").End(xlUp)).SpecialCells(xlCellTypeVisible)
DestSh.Cells(Last + 1, "B").Resize(.Rows.Count,
..Columns.Count).Value = .Value
End With

'Copy sheet name to Summary column A
DestSh.Cells(Last + 1, "A").Value = .Name
End If
End With
Next sh

btw, I've wrapped this whole section of code in a "with sh" clause.
I've added the xltypevisible in where I think it should go but with this
done I'm not sure if it will still like the following resizing section of
"(.Rows.Count, .Columns.Count)".

hth
Rob

__________________
Rob Brockett
NZ
Always learning & the best way to learn is to experience...


"tigger" wrote:

> Thanks guys - worked perfectly!
>
> The other thing I want to do is copy the visible cells in a selected range -
> code below.
>
> Any ideas where I should put .SpecialCells(xlCellTypeVisible)?
>
> Thanks
>
> For Each sh In ThisWorkbook.Worksheets
> If sh.Name <> DestSh.Name Then
> sh.AutoFilterMode = False
>
> sh.Range("A1").AutoFilter Field:=7, Criteria1:="Open"
>
> Last = LastRow(DestSh)
> shLast = LastRow(sh)
>
> 'Copy range and paste into Summary as values
> With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> .Columns.Count).Value = .Value
> End With
>
> 'Copy sheet name to Summary column A
> DestSh.Cells(Last + 1, "A").Value = sh.Name
> End If
> Next
>
> "(E-Mail Removed)" wrote:
>
> > On Nov 5, 9:04 am, tigger <tig...@discussions.microsoft.com> wrote:
> > > HI there,
> > >
> > > I'm trying to apply an autofilter to each sheet in my workbook to copy data
> > > to a summary sheet based on criteria.
> > >
> > > I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'
> > >
> > > Can anyone help?
> > >
> > > For Each sh In ThisWorkbook.Worksheets
> > > If sh.Name <> DestSh.Name Then
> > > sh.AutoFilterMode = False
> > >
> > > sh.Range("Status").AutoFilter , "Open"
> > >
> > > Last = LastRow(DestSh)
> > > shLast = LastRow(sh)
> > >
> > > 'Copy range and paste into Summary as values
> > > With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> > > DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> > > .Columns.Count).Value = .Value
> > > End With
> > >
> > > 'Copy sheet name to Summary column A
> > > DestSh.Cells(Last + 1, "A").Value = sh.Name
> > > End If
> > > Next
> > >
> > > Thanks

> >
> > Hi
> > Try this
> > sh.Range("Status").AutoFilter Field:=1, Criteria1:="Open"
> >
> > Help says Field is optional, but I got an error if I didn't specify
> > it.
> >
> > regards
> > Paul
> >
> >

 
Reply With Quote
 
=?Utf-8?B?dGlnZ2Vy?=
Guest
Posts: n/a
 
      5th Nov 2007
Needed some tweaking but works great!

Thanks for your time

With sh.Range("D2:H2", sh.Cells(sh.Rows.Count,
"D").End(xlUp)).SpecialCells(xlCellTypeVisible)
DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, .Columns.Count).Value = .Value
End With

"broro183" wrote:

> Thanks for the feedback :-)
>
> Does this work for you?
>
> For Each sh In ThisWorkbook.Worksheets
> With sh
> If .Name <> DestSh.Name Then
> .AutoFilterMode = False
>
> .Range("A1").AutoFilter Field:=7, Criteria1:="Open"
>
> Last = LastRow(DestSh)
> shLast = LastRow(sh)
>
> 'Copy range and paste into Summary as values
> With .Range("D2:H2", .Cells(.Rows.Count,
> "D").End(xlUp)).SpecialCells(xlCellTypeVisible)
> DestSh.Cells(Last + 1, "B").Resize(.Rows.Count,
> .Columns.Count).Value = .Value
> End With
>
> 'Copy sheet name to Summary column A
> DestSh.Cells(Last + 1, "A").Value = .Name
> End If
> End With
> Next sh
>
> btw, I've wrapped this whole section of code in a "with sh" clause.
> I've added the xltypevisible in where I think it should go but with this
> done I'm not sure if it will still like the following resizing section of
> "(.Rows.Count, .Columns.Count)".
>
> hth
> Rob
>
> __________________
> Rob Brockett
> NZ
> Always learning & the best way to learn is to experience...
>
>
> "tigger" wrote:
>
> > Thanks guys - worked perfectly!
> >
> > The other thing I want to do is copy the visible cells in a selected range -
> > code below.
> >
> > Any ideas where I should put .SpecialCells(xlCellTypeVisible)?
> >
> > Thanks
> >
> > For Each sh In ThisWorkbook.Worksheets
> > If sh.Name <> DestSh.Name Then
> > sh.AutoFilterMode = False
> >
> > sh.Range("A1").AutoFilter Field:=7, Criteria1:="Open"
> >
> > Last = LastRow(DestSh)
> > shLast = LastRow(sh)
> >
> > 'Copy range and paste into Summary as values
> > With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> > DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> > .Columns.Count).Value = .Value
> > End With
> >
> > 'Copy sheet name to Summary column A
> > DestSh.Cells(Last + 1, "A").Value = sh.Name
> > End If
> > Next
> >
> > "(E-Mail Removed)" wrote:
> >
> > > On Nov 5, 9:04 am, tigger <tig...@discussions.microsoft.com> wrote:
> > > > HI there,
> > > >
> > > > I'm trying to apply an autofilter to each sheet in my workbook to copy data
> > > > to a summary sheet based on criteria.
> > > >
> > > > I keep getting an error on 'sh.Range("Status").AutoFilter , "Open"'
> > > >
> > > > Can anyone help?
> > > >
> > > > For Each sh In ThisWorkbook.Worksheets
> > > > If sh.Name <> DestSh.Name Then
> > > > sh.AutoFilterMode = False
> > > >
> > > > sh.Range("Status").AutoFilter , "Open"
> > > >
> > > > Last = LastRow(DestSh)
> > > > shLast = LastRow(sh)
> > > >
> > > > 'Copy range and paste into Summary as values
> > > > With sh.Range("D2:H2", sh.Cells(sh.Rows.Count, "D").End(xlUp))
> > > > DestSh.Cells(Last + 1, "B").Resize(.Rows.Count, _
> > > > .Columns.Count).Value = .Value
> > > > End With
> > > >
> > > > 'Copy sheet name to Summary column A
> > > > DestSh.Cells(Last + 1, "A").Value = sh.Name
> > > > End If
> > > > Next
> > > >
> > > > Thanks
> > >
> > > Hi
> > > Try this
> > > sh.Range("Status").AutoFilter Field:=1, Criteria1:="Open"
> > >
> > > Help says Field is optional, but I got an error if I didn't specify
> > > it.
> > >
> > > regards
> > > Paul
> > >
> > >

 
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
Want to blank some cells when an AutoFilter is active. DocBrown Microsoft Excel Programming 9 5th Dec 2009 11:25 PM
copy data when Autofilter On and active sebastien Microsoft Excel Programming 0 19th Dec 2008 12:41 AM
Update a autofilter sheet from another sheet Don Microsoft Excel Misc 1 18th Jun 2008 12:57 PM
Copy from active sheet and paste into new sheet using info from cell in active Ingve Microsoft Excel Programming 3 23rd Jan 2006 09:57 PM
autofilter on a not-active sheet Peter Microsoft Excel Programming 2 15th Jan 2005 12:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:18 AM.