Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA Autofilter -- what if criteria doesn't exist? Error handling??? Please help...

Hi, I'm asking excel to update an autofilter with the following line:

Selection.AutoFilter Field:=61, Criteria1:="2"

However, I just noticed that 2 is not always in the list. In that
case, it doesn't auto filter anything and all rows are still visible.
Is there a way that I can get it to display zero rows if it can't
autofilter by the desired criteria?

Thanks, Rob (bertbarndoor)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default VBA Autofilter -- what if criteria doesn't exist? Error handling?

Hi,

I checked your code and it does not show any rows if I use it on my PC.

I think there must be some other lines in your code that are affecting the
view. For me the below line of code worked fine.

--
Pranav Vaidya
VBA Developer
PN, MH-India



"bertbarndoor" wrote:

Hi, I'm asking excel to update an autofilter with the following line:

Selection.AutoFilter Field:=61, Criteria1:="2"

However, I just noticed that 2 is not always in the list. In that
case, it doesn't auto filter anything and all rows are still visible.
Is there a way that I can get it to display zero rows if it can't
autofilter by the desired criteria?

Thanks, Rob (bertbarndoor)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA Autofilter -- what if criteria doesn't exist? Error handling?

Sub PrintFormat()
'
'
' VB Created 10/17/2007 by Robert Brando
'

' Updates Autofilter

Selection.AutoFilter Field:=61, Criteria1:="2"

' Widens rows as necessary

Rows("4:1000").EntireRow.AutoFit
Application.CutCopyMode = False

' Sets Print Area

Dim lastCell As Range
Set lastCell = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0)
Do Until Application.Count(lastCell.EntireRow) < 0
Set lastCell = lastCell.Offset(-1, 0)
Loop
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1),
lastCell).Address


'
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA Autofilter -- what if criteria doesn't exist? Error handling?

Nevermind, it was the row-autofit that was doing it. Thanks.

-Rob

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA Autofilter -- what if criteria doesn't exist? Error handling?

Here is my full code??? Is it one of the other lines that could be
screwing it up?

Sub PrintFormat()
'
'
' VB Created 10/17/2007
'

' Updates Autofilter

Selection.AutoFilter Field:=61, Criteria1:="2"

' Widens rows as necessary

Rows("4:1000").EntireRow.AutoFit
Application.CutCopyMode = False

' Sets Print Area

Dim lastCell As Range
Set lastCell = Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0)
Do Until Application.Count(lastCell.EntireRow) < 0
Set lastCell = lastCell.Offset(-1, 0)
Loop
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1),
lastCell).Address


'
End Sub

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
Prevent getting all rows if Autofilter criteria doesn't exist RW Excel Programming 13 November 25th 06 10:58 PM
Selection.AutoFilter Field / Criteria = criteria sometimes non-existing on worksheet markx Excel Programming 1 November 24th 06 02:52 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
3 criteria must exist in adjoining cells then rtn val from 4th SteveH Excel Discussion (Misc queries) 2 January 23rd 06 03:13 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM


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