Define print area depending on a cell value

  • Thread starter Thread starter rahmad
  • Start date Start date
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
 
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
 
Sub printmyarea()
If Range("b1") = 20 Then x = 4 Else x = 2
Range(Cells(1, 1), Cells(12, x)).PrintOut 'Preview
End Sub
 
Back
Top