Printing Filtered Data

ExcelNoviceGA

New Member
Joined
Apr 26, 2011
Messages
3
I've got a spreadsheet which I'm trying to filter and print and have fun into some issues. I've gotten the form filtered and it prints but only the first 2 filtered rows. I've pasted the code below but my "goal" is as follows (in case my garbled code doesn't reflect that).

The button, once pushed, will filter a spreadsheet based on a specific column and will then print columns A-W down to a relative row. I'm using column "H" to attempt to determine the last row because it has data in every cell (not all the columns do). Thanks for any help offered.

Private Sub TestPrint_Click()
Worksheets("2011 MPL").AutoFilterMode = False

Sheets("2011 MPL").Activate

Worksheets("2011 MPL").Range("A1").End(xlToLeft).AutoFilter _
field:=8, _
Criteria1:="GZ", _
VisibleDropDown:=True


StartCol = 1
startRow = 1
EndCol = 23
EndRow = Range("H2").SpecialCells(xlCellTypeLastCell).Row


With Worksheets("2011 MPL")
.PageSetup.PrintArea = .Range(.Cells(startRow, StartCol), .Cells(EndRow, EndCol)).Address(1, 1, xlA1, True)
.PageSetup.PaperSize = xlPaperLedger
.PageSetup.Orientation = xlPortrait
.PageSetup.FitToPagesWide = 1
.PageSetup.Zoom = False
End With

ActiveSheet.PrintOut

End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi

Try -

Code:
Dim Prrng as String
 
Prrng = "A1:H" & Endrow

then change the setup to -
Code:
.PageSetup.PrintArea = Prrng

hth
 
Upvote 0
Still yielding the same results. It prints the first 2 filtered rows which correspond to rows 19 & 21. I've noticed that there seems to be a few different ways (each with their own drawbacks or disadvantages) to find the last row and I'm wondering if there is something wrong with how I'm doing that.
 
Last edited:
Upvote 0
Hi

The following will provide you with the area that has been autofiltered -
Code:
Prrng = ActiveSheet.AutoFilter.Range.Address

and then for the PageSetup -
Code:
.PageSetup.PrintArea = .Range(Prrng).SpecialCells(xlCellTypeVisible)

If you need to resize it columnwise use -
Code:
.PageSetup.PrintArea = .Range(Prrng).Resize(,23).SpecialCells(xlCellTypeVisible)

hth
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top