Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Problems copying Autofiltered rows & SpecialCells

Hi,

I am filtering a selection based on one column NOT being zero using
Autofilter. The rows that are not zero have to be copied.

Unfortunately, it is possible for no rows to be grater than zero, so
SpecialCells returns no rows to copy and I get an error...

Here is my code:
Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

[B3:C122,G3:G122].Select

Selection.SpecialCells(xlCellTypeVisible).Copy ' <<<< ERROR HERE

How can I do this without an error... that is, check the number of rows that
are visible in my range and if it's zero, do something else...

thanks

Philip

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problems copying Autofiltered rows & SpecialCells

Dim rng as Range
Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

[B3:C122,G3:G122].Select
set rng = Nothing
On Error Resume Next
set rng = Selection.SpecialCells(xlCellTypeVisible)
on Error goto 0
if not rng is nothing then
rng.copy


end if

--
Regards,
Tom Ogilvy


"Philip" wrote in message
...
Hi,

I am filtering a selection based on one column NOT being zero using
Autofilter. The rows that are not zero have to be copied.

Unfortunately, it is possible for no rows to be grater than zero, so
SpecialCells returns no rows to copy and I get an error...

Here is my code:
Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

[B3:C122,G3:G122].Select

Selection.SpecialCells(xlCellTypeVisible).Copy ' <<<< ERROR HERE

How can I do this without an error... that is, check the number of rows

that
are visible in my range and if it's zero, do something else...

thanks

Philip



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Problems copying Autofiltered rows & SpecialCells

Looks like Tom beat me to the punch but here is my crack at it... Pretty much
the same as Tom's...

Sub test()
Dim rng As Range
Dim wks As Worksheet

Set wks = ActiveSheet

Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

On Error Resume Next
Set rng = wks.Range("B3:C122,G3:G122").SpecialCells(xlCellTy peVisible)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "No Cells"
Else
rng.Copy
End If

End Sub

HTH

"Philip" wrote:

Hi,

I am filtering a selection based on one column NOT being zero using
Autofilter. The rows that are not zero have to be copied.

Unfortunately, it is possible for no rows to be grater than zero, so
SpecialCells returns no rows to copy and I get an error...

Here is my code:
Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

[B3:C122,G3:G122].Select

Selection.SpecialCells(xlCellTypeVisible).Copy ' <<<< ERROR HERE

How can I do this without an error... that is, check the number of rows that
are visible in my range and if it's zero, do something else...

thanks

Philip

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default Problems copying Autofiltered rows & SpecialCells

thanks guys that's great.

Philip

"Jim Thomlinson" wrote:

Looks like Tom beat me to the punch but here is my crack at it... Pretty much
the same as Tom's...

Sub test()
Dim rng As Range
Dim wks As Worksheet

Set wks = ActiveSheet

Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

On Error Resume Next
Set rng = wks.Range("B3:C122,G3:G122").SpecialCells(xlCellTy peVisible)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "No Cells"
Else
rng.Copy
End If

End Sub

HTH

"Philip" wrote:

Hi,

I am filtering a selection based on one column NOT being zero using
Autofilter. The rows that are not zero have to be copied.

Unfortunately, it is possible for no rows to be grater than zero, so
SpecialCells returns no rows to copy and I get an error...

Here is my code:
Selection.AutoFilter Field:=7, Criteria1:="<0.00000000"

[B3:C122,G3:G122].Select

Selection.SpecialCells(xlCellTypeVisible).Copy ' <<<< ERROR HERE

How can I do this without an error... that is, check the number of rows that
are visible in my range and if it's zero, do something else...

thanks

Philip

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
rogue rows appear in autofiltered sort dmich Excel Discussion (Misc queries) 0 January 11th 09 04:49 PM
Copying to an autofiltered list Phil Excel Discussion (Misc queries) 3 June 30th 05 02:08 PM
Deleting AutoFiltered Rows Nirmal Singh Excel Programming 11 February 7th 05 06:41 PM
Count Autofiltered Rows? simsjr Excel Programming 1 January 26th 05 11:21 PM
Help to hide rows, SpecialCells(xlCellTypeBlanks) doesn't work... Gunnar Johansson Excel Programming 6 August 15th 04 11:54 AM


All times are GMT +1. The time now is 08:21 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"