ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Setting Print Area (https://www.excelbanter.com/excel-programming/401816-setting-print-area.html)

Mike[_122_]

Setting Print Area
 
Hi,
Is it possible to set/reset the print area according to a cell value?

e.g.:-
if A1 = 1 then set print area to B1:B10
if A1 = 2 then set print area to C1:C10
etc.
TIA
Mike



Don Guillett

Setting Print Area
 
Right click sheet tabview codeinsert this. Now when you change cell a1 the
column range will print automatically. After testing change printpreview to
printout

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$A$1" Then Exit Sub
Range(Cells(1, Target), Cells(10, Target)).PrintPreview
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Hi,
Is it possible to set/reset the print area according to a cell value?

e.g.:-
if A1 = 1 then set print area to B1:B10
if A1 = 2 then set print area to C1:C10
etc.
TIA
Mike




Mike H

Setting Print Area
 
You could do this

Alt+f11 to open VB editor. Double click 'This workbook' and paste this in

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Sheets("Sheet1").Range("A1").Value = 1 Then
ActiveSheet.PageSetup.PrintArea = "$B$1:$B$10"
ElseIf Sheets("Sheet1").Range("A1").Value = 2 Then
ActiveSheet.PageSetup.PrintArea = "$C$1:$C$10"
Else
Cancel = True
End If
End Sub

Mike

"Mike" wrote:

Hi,
Is it possible to set/reset the print area according to a cell value?

e.g.:-
if A1 = 1 then set print area to B1:B10
if A1 = 2 then set print area to C1:C10
etc.
TIA
Mike




Don Guillett

Setting Print Area
 
for one column to the right
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$A$1" Then Exit Sub
Range(Cells(1, Target+1), Cells(10, Target+1)).PrintPreview
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Right click sheet tabview codeinsert this. Now when you change cell a1
the column range will print automatically. After testing change
printpreview to printout

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$A$1" Then Exit Sub
Range(Cells(1, Target), Cells(10, Target)).PrintPreview
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike" wrote in message
...
Hi,
Is it possible to set/reset the print area according to a cell value?

e.g.:-
if A1 = 1 then set print area to B1:B10
if A1 = 2 then set print area to C1:C10
etc.
TIA
Mike






All times are GMT +1. The time now is 11:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com