View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
bertbarndoor bertbarndoor is offline
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