Define print area depending on a cell value

R

rahmad

How to write a code to determine print area and depending
on a cell value.
Let say cell A and cell B.If cell B has a certain value,then
the print area is cell A,B,C,D ,so when the worksheet is printed,it
will only include cell A,B,C,D.But if the cell B is blank or has another
certain value,the print area is cel A,B only.

Please help to do it programatically?I have not much experience
with Excel VBA.Thank's
 
M

Mark Ivey

Here is one example...

Mark Ivey


Sub SetPrintArea()

If Range("B1").Value = "" Then
ActiveSheet.PageSetup.PrintArea = "=" & _
ActiveSheet.Range("A1:B10").Address
ElseIf Range("B1").Value <> "" Then
ActiveSheet.PageSetup.PrintArea = "=" & _
ActiveSheet.Range("A1:D10").Address
End If

End Sub
 
D

Don Guillett

Sub printmyarea()
If Range("b1") = 20 Then x = 4 Else x = 2
Range(Cells(1, 1), Cells(12, x)).PrintOut 'Preview
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top