Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default VBA code for if no visible cells after filter goto next stage

I an running filters in VBA then copying the results to another worksheet on
the next available line. I have a challenge, that when there is nothing to
copy (i.e. the filter results are blank), I cannot get the VBA to go to the
next stage.

I have tried

Selection.AutoFilter Field:=19, Criteria1:="<"

Sheets("IMPORT").Activate
Sheets("IMPORT").Range("B2:B120").Select

If Selection.SpecialCells(xlCellTypeVisible) Then

'do something

else

'do something else

end if

But this results in an error.

Any help please.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default VBA code for if no visible cells after filter goto next stage

Hi,

If you try and select visible cells in a filtered range and there are none
an error is generated and you can use this

With Sheets("IMPORT")
Selection.AutoFilter Field:=19, Criteria1:="<"
On Error GoTo enditall
Set rng = .AutoFilter.Range.Offset(1,
0).Resize(.AutoFilter.Range.Rows.Count - 1, 1) _
..SpecialCells(xlCellTypeVisible)
End With
'rng exists
'Do things
enditall:
'no visible cells
'do something else

"thomsonpa" wrote:

I an running filters in VBA then copying the results to another worksheet on
the next available line. I have a challenge, that when there is nothing to
copy (i.e. the filter results are blank), I cannot get the VBA to go to the
next stage.

I have tried

Selection.AutoFilter Field:=19, Criteria1:="<"

Sheets("IMPORT").Activate
Sheets("IMPORT").Range("B2:B120").Select

If Selection.SpecialCells(xlCellTypeVisible) Then

'do something

else

'do something else

end if

But this results in an error.

Any help please.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default VBA code for if no visible cells after filter goto next stage

Looks like this will work, thank you very much. The enditall was what I was
looking for, I will use this again in future.
I don't know what I would do if it wasn't for this discussion group. It
helps me with so much.

Thank you, and keep up the good work.

"Mike H" wrote:

Hi,

If you try and select visible cells in a filtered range and there are none
an error is generated and you can use this

With Sheets("IMPORT")
Selection.AutoFilter Field:=19, Criteria1:="<"
On Error GoTo enditall
Set rng = .AutoFilter.Range.Offset(1,
0).Resize(.AutoFilter.Range.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
End With
'rng exists
'Do things
enditall:
'no visible cells
'do something else

"thomsonpa" wrote:

I an running filters in VBA then copying the results to another worksheet on
the next available line. I have a challenge, that when there is nothing to
copy (i.e. the filter results are blank), I cannot get the VBA to go to the
next stage.

I have tried

Selection.AutoFilter Field:=19, Criteria1:="<"

Sheets("IMPORT").Activate
Sheets("IMPORT").Range("B2:B120").Select

If Selection.SpecialCells(xlCellTypeVisible) Then

'do something

else

'do something else

end if

But this results in an error.

Any help please.

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
Auto Filter - Add visible cells Doobrifurkin Excel Worksheet Functions 3 September 2nd 08 01:16 PM
Copy only visible cells after filter is applied/ sum after filter MAM Excel Worksheet Functions 0 April 9th 08 04:09 AM
Filling both hidden and visible cells once a filter has been applied Corrie Excel Programming 0 December 28th 06 05:20 PM
how do i select all the visible cells only when using auto filter shaurabh Excel Discussion (Misc queries) 4 June 25th 06 07:32 AM
Goto Next VISIBLE cell below Rasmus[_2_] Excel Programming 5 May 24th 04 04:26 AM


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