exclude blank cells from print range

  • Thread starter Thread starter Brenda J
  • Start date Start date
B

Brenda J

I'm creating a macro that puts a formula in all rows of
one column and shows the cells as blank after the list of
records ends. I autofilled the formula to all rows to
accommodate any size list, but now print preview shows
thousands of pages, even though the list only has several
hundred rows with text in them. How can I automatically
exclude cells from the print area that are at the end of
the list and only contain a formula, no text? The number
of records varies each time, and I want to do this within
the macro so user's don't have to manually set the print
area.
 
Hi
you could easily set the printarea in your macro. Try the following to
do this (change the range to your needs)
sub foo()
dim wks
dim lastrow
dim rng

set wks = activesheet
LastRow = wks.Cells(Rows.Count, "A").End(xlUp).row
set rng = wks.range("A1:G" & lastrow)
wks.pagesetup.printarea = rng.address
wks.printout
end sub
 
Back
Top