View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Héctor Miguel Héctor Miguel is offline
external usenet poster
 
Posts: 434
Default Variable print area via a macro

hi, Andrew !

I need a VBA code I can run via a macro.
I have a table of data in Sheet1, say starting in cell A1 and finihsing in Z250 - its called the Range.
I only want it to print rows that have a certain value in column A.
For example, if A3, A21, A45 all have "incomplete" as their value
then only these 3 rows would be printed below the set Print Titles.
I also need the option to automatically hide or not print some columns across the page
when printing using this macro, e.g. columns D, F and H.
Any help with this would be really appreciated. Thanks, Andrew.


copy/paste (or type) the following on each type of code module and...
if any doubts (or further information)... would you please comment ?

hth,
hector.

1) in your workbook code module (ThisWorkbook)

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With Worksheets("sheet1")
.Range("d1,f1,h1").EntireColumn.Hidden = True
.Range("a1").AutoFilter 1, "incomplete"
End With
Application.OnTime Now, "Restore"
End Sub

2) in a standard code module

Option Private Module
Sub Restore()
With Worksheets("sheet1")
.Range("d1,f1,h1").EntireColumn.Hidden = False
.Range("a1").AutoFilter
End With
End Sub