VBA help for Dynamic Print Range

mwtharp

New Member
Joined
Aug 18, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
There are about 700 slicers that I need to filter through to publish a PDF invoice. The invoice is a header and some information, followed by a pivot table at the bottom that shows the line items. The pivot table can be anywhere from 1 page to 100 pages depending on the invoice. I am trying to figure out how to have the print area changed each time the slicer is changed in my VBA. I am fairly novice to VBA, and have used Access in the past for invoicing, but client wants to use Excel for this one. I have two issues (or three or more) issues with the VBA so far:

1) The print area will grow but not shrink
2) I need to add an If to look in cell F7. I want the invoice to not be published if F7 = 0
3) I'm not certain my slicer selection is working, but it seems to

Any advice is appreciated!

here is what I have so far:

Sub Filterpublish()



Dim LastRow As Long
LastRow = Range("A:F").SpecialCells(xlCellTypeLastCell).Row
ActiveSheet.PageSetup.PrintArea = "$A$2:$G$" & LastRow



'Invoice 1


ActiveWorkbook.SlicerCaches("Slicer_Guar_Name").ClearManualFilter

With ActiveWorkbook.SlicerCaches("Slicer_Guar_Name")
.SlicerItems("Invoice 1").Selected = True



ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"path for publishing here" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, ignorePrintAreas _
:=False, OpenAfterPublish:=False

End With


'Invoice 2
ActiveWorkbook.SlicerCaches("Slicer_Guar_Name").ClearManualFilter

With ActiveWorkbook.SlicerCaches("Slicer_Guar_Name")
.SlicerItems("Invoice 2").Selected = True


ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"path for publishing here" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, ignorePrintAreas _
:=False, OpenAfterPublish:=False

End With

'
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I would consider using " LastRow = worksheetfunction.counta(range("a1:a100"))" that way it will count how many cells are being used. You may need to change the range but keep it in one column or you will run into problems. Hope this helps!

I may not have helped everything depending on other errors but this is what I saw could make it better.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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