Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 358
Default Variable print area via a macro

Hi there,

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
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


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 358
Default Variable print area via a macro

Hi there and thanks for your quick response, very kind. That does work but I
have a few questions, please;

1) In cell AA1 I have a drop down list with the different option for
printing - i.e incomplete, finished, archived etc - the selected value in
this cell is what it should filter by. I also have another drop down list in
AB1 that depending on the text (i.e partial report or full report) indicates
which columns should be hidden when printing. Partial Report should hides
columns D,E,F and Full report only hides column S,T,V,W. How can these be
intergrated into the code so as I change the option the screen the print
report also changes? How would I have to show the text (column to hide) in
AB1 so that the code accepts it?

2) In the workbook there are 15 sheets total and this functionality needs to
work on all of the sheets - only one sheet is printed at any one time, but
each sheet has the drop down options to choose from etc. My VBA is not very
good, what do I have to change or copy in VBA to make this work as described
on each sheet!

3) On each worksheet I need a title to appear which comes from the text in
cell AC1 - how can this work so that it always appears, regardless of the
filtering? The title is different for each of the worksheets in the file.

Hopefully this is not too confusing, await your thoughts, Thanks again.



"Héctor Miguel" wrote:

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



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 434
Default Variable print area via a macro

hi, Andrew !

try with the following... (I hope my undertanding was correct). I added some comments (just in case)
I'm not sure if (AB1 range) contents is Full Report / Partial Report (or just Full / Partial) -?-

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)
' make sure there is ONLY ONE sheet selected to print ... '
If ActiveWindow.SelectedSheets.Count 1 Then _
Cancel = True: MsgBox "Please, select ONE (single) Sheet ONLY !"
' identify which are the columns to hide (& show later) '
Cols2Hide = IIf(LCase(Range("ab1")) = "full", "s1:t1,v1:w1", "d1:f1")
' set the document "Title" as a CenterHeader in Page Setup '
ActiveSheet.PageSetup.CenterHeader = Range("ac1").Text
' hide the columns '
Range(Cols2Hide).EntireColumn.Hidden = True
' filter according AA1 contents '
Range("a1").AutoFilter 1, Range("aa1").Text
' call the restore procedure (when finished) '
Application.OnTime Now, "Restore"
End Sub

2) in a standard code module

Option Private Module
Public Cols2Hide As String
Sub Restore()
Range(Cols2Hide).EntireColumn.Hidden = False
Range("a1").AutoFilter
End Sub

__ OP __
1) In cell AA1 I have a drop down list with the different option for printing - i.e incomplete, finished, archived etc
- the selected value in this cell is what it should filter by.
I also have another drop down list in AB1 that depending on the text (i.e partial report or full report)
indicates which columns should be hidden when printing. Partial Report should hides columns D,E,F
and Full report only hides column S,T,V,W.
How can these be intergrated into the code so as I change the option the screen the print report also changes?
How would I have to show the text (column to hide) in AB1 so that the code accepts it?

2) In the workbook there are 15 sheets total and this functionality needs to work on all of the sheets
- only one sheet is printed at any one time, but each sheet has the drop down options to choose from etc.
My VBA is not very good, what do I have to change or copy in VBA to make this work as described on each sheet!

3) On each worksheet I need a title to appear which comes from the text in cell AC1
- how can this work so that it always appears, regardless of the filtering?
The title is different for each of the worksheets in the file...



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 358
Default Variable print area via a macro

iThanks, I will give that a go now, but hopefully three last questions, please;

1) I was incorrect before re only the 'full' or partial' print options -
there will in fact be 5 print options from cell AB1, each hiding different
columns. How would I expend the formulae to include these?

2) Also, for some of the print options in AB1 I need to also hide certain
header rows - where would this be best to go in the formulae?

3) is there a way for a certain print options in AB1 it can print 'portrait'
rather than 'landscape'? landscape is the default for this workbook...

Look forward to your response, thanks again, Andrew.

"Héctor Miguel" wrote:

hi, Andrew !

try with the following... (I hope my undertanding was correct). I added some comments (just in case)
I'm not sure if (AB1 range) contents is Full Report / Partial Report (or just Full / Partial) -?-

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)
' make sure there is ONLY ONE sheet selected to print ... '
If ActiveWindow.SelectedSheets.Count 1 Then _
Cancel = True: MsgBox "Please, select ONE (single) Sheet ONLY !"
' identify which are the columns to hide (& show later) '
Cols2Hide = IIf(LCase(Range("ab1")) = "full", "s1:t1,v1:w1", "d1:f1")
' set the document "Title" as a CenterHeader in Page Setup '
ActiveSheet.PageSetup.CenterHeader = Range("ac1").Text
' hide the columns '
Range(Cols2Hide).EntireColumn.Hidden = True
' filter according AA1 contents '
Range("a1").AutoFilter 1, Range("aa1").Text
' call the restore procedure (when finished) '
Application.OnTime Now, "Restore"
End Sub

2) in a standard code module

Option Private Module
Public Cols2Hide As String
Sub Restore()
Range(Cols2Hide).EntireColumn.Hidden = False
Range("a1").AutoFilter
End Sub

__ OP __
1) In cell AA1 I have a drop down list with the different option for printing - i.e incomplete, finished, archived etc
- the selected value in this cell is what it should filter by.
I also have another drop down list in AB1 that depending on the text (i.e partial report or full report)
indicates which columns should be hidden when printing. Partial Report should hides columns D,E,F
and Full report only hides column S,T,V,W.
How can these be intergrated into the code so as I change the option the screen the print report also changes?
How would I have to show the text (column to hide) in AB1 so that the code accepts it?

2) In the workbook there are 15 sheets total and this functionality needs to work on all of the sheets
- only one sheet is printed at any one time, but each sheet has the drop down options to choose from etc.
My VBA is not very good, what do I have to change or copy in VBA to make this work as described on each sheet!

3) On each worksheet I need a title to appear which comes from the text in cell AC1
- how can this work so that it always appears, regardless of the filtering?
The title is different for each of the worksheets in the file...






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 434
Default Variable print area via a macro

hi, Andrew ! (see inline)

1) I was incorrect before re only the 'full' or partial' print options
- there will in fact be 5 print options from cell AB1, each hiding different columns.
How would I expend the formulae to include these?


1) change this:
Cols2Hide = IIf(LCase(Range("ab1")) = "full", "s1:t1,v1:w1", "d1:f1")

- to something like this:
Select Case LCase(Range("ab1"))
Case "full": Cols2Hide = "s1:t1,v1:w1"
Case "partial": Cols2Hide = "d1:f1"
' Add more Cases ... '
End Select

2) Also, for some of the print options in AB1 I need to also hide certain header rows
- where would this be best to go in the formulae?


2) using something like the above ?
(I can't get clearly which the cases are and what conditions to apply)
- add another variable in the standard code module (Rows2Hide ?)
- use as reference column "a" and the row-number to build the string
- use .EntireRow.Hidden (instead of .EntireColumn.Hidden)
- don't forget to reverse in the "Restore" procedure

3) is there a way for a certain print options in AB1 it can print 'portrait' rather than 'landscape'?
landscape is the default for this workbook...


3) (again) when "the condition" is meet...
- add another line to apply: - ActiveSheet.PageSetup.Orientation = xlPortrait
- don't forget to reverse in the "Restore" procedu - ActiveSheet.PageSetup.Orientation = xlLandscape

if any doubts (or further information)... would you please comment ?
hth,
hector.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using named range to extend print area for variable number of columns Pierre Excel Worksheet Functions 3 April 10th 08 05:51 PM
How do you set up a macro to reset the print area? Stuck2 Excel Discussion (Misc queries) 0 January 30th 06 03:50 PM
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
Create a print macro that would automatically select print area? wastedwings Excel Worksheet Functions 7 August 22nd 05 10:36 PM
Variable print area BOBF Excel Discussion (Misc queries) 2 March 22nd 05 01:47 PM


All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"