PDA

View Full Version : Macro to print a page-or not, based on a cells content.


rsdjimbie
Sep 27, 2009, 11:26 AM
Sub Printing()
'
' Printing Macro
' Macro recorded 15/12/2005 by Lenah
'
' Keyboard Shortcut: Ctrl+p
'
Application.ScreenUpdating = False
Sheets("Invoice").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=4, Collate:=True
Sheets("SAD500").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

'Print this sheet only if cell AX4=>2
Sheets("SAD501-1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

'Print this sheet only if cell AX4=3
Sheets("SAD501-2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True


Sheets("Manhood").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Invoice").Select
Application.ScreenUpdating = True
End Sub


Hope the code sample is sufficient.
Thanks a mil.

JBeaucaire
Sep 27, 2009, 11:44 PM
Try this:

Sub Printing()
'
' Printing Macro
' Macro recorded 15/12/2005 by Lenah
' Edited by JBeaucaire (27/9/2009)
' Keyboard Shortcut: Ctrl+p
'
Application.ScreenUpdating = False

Sheets("Invoice").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=4, Collate:=True

Sheets("SAD500").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

'Print this sheet only if cell AX4=>2
If Sheets("SAD501-1").Range("AX4") >= 2 Then
Sheets("SAD501-1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

'Print this sheet only if cell AX4=3
If Sheets("SAD501-2").Range("AX4") = 3 Then
Sheets("SAD501-2").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

Sheets("Manhood").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
Sheets("Invoice").Activate
Application.ScreenUpdating = True
End Sub

rsdjimbie
Oct 1, 2009, 11:24 AM
Works a treat, thank you very much.