i tried running this code and its fine in so long as i am on that worksheet but i want to be to have this executed without actually printing a page, since i am doing the emailing thing, - so i want to execute it so it will either display two pages or one depending on the data entered, and thereby printing the last row.  but cant figure out how to have it done in a macro without having it not actually printout the page, just want it to calculate, so when i do create a pdf from email it will show the results, does that make sense...

Sub PrintBB()

   Application.ScreenUpdating = False
   Sheets("BillBack").Visible = True

   Dim lastRow1 As Long, i As Long
   For i = 3 To 67
     If Len(Trim(Cells(i, "S").Value)) > 0 Then
         lastRow1 = i
    End If
   ActiveSheet.PageSetup.PrintArea = "C2:S" & lastRow1
   ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

   Worksheets("BillBack").Visible = xlSheetVeryHidden
   Application.ScreenUpdating = True
End Sub



If you generate a PDF, it should be the same whether you have printed the sheet or you haven't as long as printing the sheet doesn't establish new formatting (in other words if you have a beforeprint event that changes the footer or something than that routine would need to be run to format the footer).   

so what you say doesn't make much sense to me.   Try formatting the sheet as you want to see it and then run you code without printing the sheet.  I would expect it to be formatted as it would have looked if it were printed with just the existing formatting.

But again, tha tis only a guess on my part.    

Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Tom Ogilvy


Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]


Extensive experience.

Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2017 About.com. All rights reserved.

[an error occurred while processing this directive]