在VBA中过滤并保存为pdf

我想移动一个filter,并在移到下一个filter项目之前,将过滤后的页面上显示的内容打印到一个pdf文件中。 推动这个想法是,我需要报告我所在州的每个学区的学校build筑信息。 我现在有数据坐在一张桌子(如果代码能够更好地工作,可以很容易地与一个切片机一起使用),并根据需要设置滤镜。 列的长度将随着分区的变化而变化以适应不同的尺寸。 目前,我的代码不起作用。 我需要帮助找出原因。

Sub ShiftandPrint() Dim i As Integer i = 1 For cl = 1 To Columns.Count n = WorksheetFunction.CountA(Columns(cl)) Next Do While Cells(3, i).Value <> "" With Sheet1 .AutoFilterMode = False .Range("n").AutoFilter .Range("n").AutoFilter Field:=1, Criteria1:=Cell(3, i) End With Dim fName As String With ActiveSheet fName = .Range("A1").Value & .Range("A2").Value .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\My Documents\" & fName, Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End With i = i + 1 Loop End Sub 

谢谢你的帮助!