Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Copying nothing/everything when an autofilter returns no results? XL2003

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Copying nothing/everything when an autofilter returns no results? XL2003

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying format controls - xl2003 Steve Jones Excel Discussion (Misc queries) 3 December 18th 08 02:21 PM
Terminating autofilter removes commandbuttons (xl2000, not in xl2003) Rob[_5_] Excel Programming 3 August 29th 07 08:07 PM
Copying, Pasting Autofilter results to a region more specific than a specified worksheet. [email protected] Excel Programming 1 March 28th 07 06:16 PM
Switch off Sort with Autofilter in XL2003 Roger Govier Excel Programming 5 December 4th 06 10:02 PM
Copying And Renaming Sheets XL2003 Kevin H. Stecyk[_2_] Excel Programming 2 May 30th 06 10:41 PM


All times are GMT +1. The time now is 04:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"