PRINT IF in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to have a file print in legal size if I have 56 lines filled in
otherwise print in regular letter size. Does anyone know how to write this
in VBA. help would be appreciated. thanks
 
If Row - nr > 56 Then ActiveSheet.PageSetup.PaperSize = xlPaperLegal
xlPaperLetter Letter (8-1/2 in. x 11 in.)
xlPaperA4 A4 (210 mm x 297 mm)
 
I copied it and placed it in the macro but I get a syntex error, what am i
doing wrong?
 
You copied and pasted?
then you have not taught your computer how to count the row numbers yet.
 
I guess not. The syntex error shows up on the following.
xlPaperLetter Letter (8-1/2 in. x 11 in.)
xlPaperA4 A4 (210 mm x 297 mm)
 
These two are only xlConstants for your information if you wish to change
the paper sizes. They should not remain in the code.

also how does the computer (and ourselves) know how many rows your print
area have? When know, adjust row_nr to suit please.
 
The number of rows changes hourly. Is there a way for the macro to count the
number of rows and then based on the number if > 55 make it legal size.
 
Try this

LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
 
I put both of the tips in the macro but it still did not count the number of
rows with data and make it legal size if the nbr of rows are greater than 56.
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
If Row - nr > 46 Then ActiveSheet.PageSetup.PaperSize = xlPaperLegal
 
change If Row - nr > 46 to
if lastrow>56

Curt D. said:
I put both of the tips in the macro but it still did not count the number of
rows with data and make it legal size if the nbr of rows are greater than 56.
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
If Row - nr > 46 Then ActiveSheet.PageSetup.PaperSize = xlPaperLegal
 

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

Back
Top