PC Review


Reply
Thread Tools Rate Thread

Copying nothing/everything when an autofilter returns no results? XL2003

 
 
ker_01
Guest
Posts: n/a
 
      23rd Oct 2008
I have a large dataset on "Worksheet A". I use VBA to apply to autofilter
criteria to the worksheet, copy the (visible) results, and paste them on to
"Worksheet B".

The problem I'm running into is that it appears that when the autofilter
criteria result in no visible rows, the entire (hidden) data set is copied
from "Worksheet A" using the code below.

Is there a good way to determine if there are usable rows once the
autofilter is applied, but before the copy/paste operation? I'd like to opt
out and not copy anything if there are no visible records.

Thank you,
Keith


Private Sub CommandButton1_Click()

'Collect sort information
SortDept = Sheet12.Range("B2").Value
SortDate = Sheet12.Range("E2").Value

'clear previous data "sheet B" before going to get new data
Sheet12.Activate
Sheet12.Rows("28:5000").Select
Selection.Delete Shift:=xlUp
Sheet12.Range("A1").Activate

'get the data from "Sheet A"
Sheet16.Activate
Sheet16.Select
Sheet16.Cells.Select
Sheet16.Range("A1").Activate
Selection.AutoFilter
Selection.AutoFilter Field:=10, Criteria1:=SortDept
Selection.AutoFilter Field:=20, Criteria1:=SortDate

'This is where I'd like to know if there are any results returned from
the autofilter

'This selects just the unhidden rows, excluding the header row
Sheet16.Range("A2:X50001").Select

Selection.Copy
Sheet12.Select
Sheet12.Range("A28").Select
ActiveSheet.Paste
Sheet16.Activate
Application.CutCopyMode = False
Selection.AutoFilter
Sheet16.Range("A1").Select
Sheet12.Activate

End Sub


 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      23rd Oct 2008
SpecialCells(xlCellTypeVisible) will throw an error if no cells are visible.
--
Jim Cone
Portland, Oregon USA


"ker_01"
wrote in message
I have a large dataset on "Worksheet A". I use VBA to apply to autofilter
criteria to the worksheet, copy the (visible) results, and paste them on to
"Worksheet B".
The problem I'm running into is that it appears that when the autofilter
criteria result in no visible rows, the entire (hidden) data set is copied
from "Worksheet A" using the code below.
Is there a good way to determine if there are usable rows once the
autofilter is applied, but before the copy/paste operation? I'd like to opt
out and not copy anything if there are no visible records.
Thank you,
Keith
-snip-
 
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
change XL2003 autofilter's arrow color =?Utf-8?B?Qks=?= Microsoft Excel Misc 9 5th Feb 2010 11:42 AM
Exclude header row when copying autofilter results? (XL2003) ker_01 Microsoft Excel Programming 1 19th Jan 2010 12:09 AM
Copying, Pasting Autofilter results to a region more specific than a specified worksheet. feature86@yahoo.com Microsoft Excel Programming 1 28th Mar 2007 06:16 PM
Switch off Sort with Autofilter in XL2003 Roger Govier Microsoft Excel Programming 5 4th Dec 2006 10:02 PM
Re: Results of Autofilter for blanks returns non-blank cells Dave Peterson Microsoft Excel Misc 0 12th Aug 2004 01:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 AM.