How to Print a Range in VBA: Excel Setup and Examples

VBA & macros · Updated November 16, 2026

To print a specific Excel range with VBA, assign it to a Range variable and call its PrintOut method, such as ws.Range("A1:F25").PrintOut. If you want to print a worksheet using a defined region, set its PageSetup.PrintArea first, then call Worksheet.PrintOut.

What “print a range” means in VBA

A range is one or more cells on a worksheet. Printing one usually means sending just that block of cells to Excel’s current printer, rather than printing the whole sheet or workbook. The code can identify a fixed address, such as A1:F25, or build a range based on changing data.

There are two closely related approaches:

  • Print a Range object: Call PrintOut on the range itself. This is a direct choice when the macro should print a particular block.
  • Set a worksheet print area: Assign an address to PageSetup.PrintArea, then print the worksheet. This is useful when the worksheet’s regular print settings should include only that region.

Both approaches use Excel’s page setup and the printer available to the computer. VBA selects what to print; it does not independently decide the physical page size, margins, scaling, or printer capabilities.

Print a range directly

Use a worksheet variable to identify the correct sheet, then call PrintOut on the desired cells. This complete example prints A1:F25 on a worksheet named Invoice:

Sub PrintInvoiceRange()
    Dim ws As Worksheet
    Dim printRange As Range

    ' Identify the worksheet and cells to print.
    Set ws = ThisWorkbook.Worksheets("Invoice")
    Set printRange = ws.Range("A1:F25")

    ' Send one collated copy to the current printer.
    printRange.PrintOut Copies:=1, Collate:=True
End Sub

ThisWorkbook refers to the workbook containing the macro. That is often safer than ActiveWorkbook, which can refer to a different workbook if the user switches files. The worksheet name must match a sheet tab exactly; otherwise, VBA raises an error. The Copies argument controls the number of copies, and Collate determines how multiple copies of multi-page output are grouped.

For a quick one-off, the essential statement can be as short as Worksheets("Invoice").Range("A1:F25").PrintOut. Using declared variables, as in the full example, makes it easier to maintain and troubleshoot the macro.

Set a print area and print the worksheet

A print area is a worksheet setting that marks which cells should be included when that sheet is printed. It is convenient if you want worksheet-level printing to repeatedly use the same block, or if other print settings are also being controlled. For example:

Sub PrintInvoiceSheet()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets("Invoice")

    ' Limit worksheet printing to this cell block.
    ws.PageSetup.PrintArea = "$A$1:$F$25"
    ws.PrintOut Copies:=1
End Sub

The address is written with absolute references, which is a common way to specify a fixed print area. Setting it changes the worksheet’s page setup; it is not merely a temporary selection. The print area can remain in the workbook after the macro runs and may affect later manual printing or other macros.

To remove a previously assigned print area, set PrintArea to an empty string. For instance, with ws already set to the intended worksheet, use ws.PageSetup.PrintArea = "". If a macro should temporarily change the area and then restore the previous one, store the original value in a String variable and put the restoration in a cleanup section. That avoids leaving a changed page setup behind if the procedure is reused.

Choose the right printing method

Use Range.PrintOut when the macro’s task is simply to print a particular range. It keeps the target explicit in the print statement and is usually easiest for a fixed report, receipt, or form. Use PageSetup.PrintArea with Worksheet.PrintOut when the worksheet’s print area is part of its intended layout or when you are coordinating it with worksheet page setup.

Think about what should happen the next time someone prints the sheet manually. If the print area should stay restricted to the report, saving it as a worksheet setting may be appropriate. If the macro should print a one-time selection without changing the sheet’s ongoing setup, printing the range directly is generally clearer.

For a table whose length changes, calculate the last row rather than hard-coding it. For example, a macro can find the last used row in a known column and construct a range from A1 through that row. Choose the column carefully: a column with blanks inside the data may not reliably identify the final record, and a column with unrelated notes below the table may include unwanted cells.

Preview before sending pages to the printer

Printing is an external action, and a macro’s output is not easily undone. Use PrintPreview while developing or when users should inspect a report before printing. A worksheet print area can be set before previewing the sheet, so the preview reflects the worksheet-level print region:

Sub PreviewInvoice()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets("Invoice")

    ' Preview the defined area instead of printing immediately.
    ws.PageSetup.PrintArea = "$A$1:$F$25"
    ws.PrintPreview
End Sub

Preview is useful for catching clipped columns, unexpected blank pages, or a report that has been scaled too small. It cannot guarantee the same result on every computer: paper size, printer driver, default printer, and installed fonts can affect pagination. Check the preview on the machine and printer that will produce the final output when exact page layout matters.

Control page layout and scaling

The range tells Excel which cells to print, but the page setup determines how they fit on paper. A wide range may spill across multiple pages; a very tall range may produce many pages. Common page setup choices include orientation, scaling, margins, and whether rows or columns repeat on each printed page.

For example, this code sets landscape orientation and fits the printout to one page wide while allowing as many pages vertically as needed:

Sub SetInvoicePageLayout()
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets("Invoice")

    ' Fit the output across one page without forcing one page tall.
    With ws.PageSetup
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 0
    End With
End Sub

Setting Zoom to False allows the fit-to-page properties to control scaling. Fitting a large range onto one page wide can make text difficult to read, so inspect the preview rather than assuming fewer pages means better output. If a report has column headings, Excel’s page setup can also repeat selected rows at the top of each printed page; that setting is useful for long tables but does not change which cells belong to the print range.

Print changing or multiple blocks of data

For a report that grows over time, the macro can determine its extent at run time. A common pattern is to find the last occupied row in a dependable key column, then combine that row number with fixed starting and ending columns. The data layout matters: if column A contains a header and a value on every record, it can be a reasonable guide; if records may have blanks in A, use a more reliable column or a table’s data range instead.

Several separate blocks are less straightforward than one rectangular range. A noncontiguous range can be represented in VBA, but its printed layout may not match the idea of one neatly joined report. If the sections must appear together in a particular order, consider arranging them in a single contiguous report area or copying them to a dedicated report sheet, then previewing that sheet. Printing each block separately is another option, but it can create separate print jobs or pages, depending on how the calls and printer handle the output.

When a report range depends on a filter, decide whether hidden rows should be included. A normal rectangular address can encompass rows hidden by filtering or manual hiding, while visible-cells-only selection is a separate concern. Test the exact data state the macro is meant to handle, especially if users can change filters before running it.

Common problems and practical safeguards

  • Wrong sheet or “Subscript out of range”: Check the workbook reference and exact worksheet tab name. Avoid relying on whichever sheet happens to be active.
  • Nothing appears to happen: Excel may send output directly to the current default printer without opening a dialog. Confirm the printer selection and queue, and use preview during development.
  • Unexpected pages or tiny text: Review the print area, page breaks, orientation, scaling, and paper size. A range can be correct while the page setup is not.
  • Old cells still print: A prior PrintArea setting may remain on the worksheet. Inspect or clear it if the macro intends to print the sheet without a restriction.
  • Changes are difficult to reverse: A print job cannot be undone with Ctrl+Z. Save a copy of the workbook before running a macro, particularly when it changes page setup or processes many sheets.

Keep output actions separate from data-changing actions where possible. A preview button or a confirmation prompt can reduce accidental print runs, and a clear worksheet name and range make the code easier to review. If a printer error occurs, Excel may raise an error or rely on the operating system’s print queue; code should not assume that a call guarantees paper was successfully produced.

Excel on Windows, Mac, and the web

This guidance targets Excel for Microsoft 365 on Windows. VBA macros can also be used in the desktop Excel app for Mac, though printer availability, driver options, and some dialog details depend on macOS and the installed printer. The VBA concepts of a range, print area, and print method are broadly similar, but verify the result on the target platform if the workbook is shared across Windows and Mac.

Excel for the web does not run VBA macros. A workbook containing VBA can be opened there, but the macro must be run in a desktop version of Excel. On Windows, Ctrl+P opens Excel’s print interface; on Mac, Command+P is the corresponding shortcut. These shortcuts are for manual printing, not substitutes for a VBA procedure.

Frequently Asked Questions

What is the simplest VBA code to print a range?
Use a worksheet and range reference followed by PrintOut, such as Worksheets("Sheet1").Range("A1:D10").PrintOut. A full macro should declare variables and identify the intended workbook explicitly.

How do I print only the used cells in a worksheet?
Identify the actual data boundaries and print that range. “Used cells” can include formatting left behind beyond the visible data, so avoid assuming that Excel’s used range always equals the report you want. For repeatable output, define the columns and find the last meaningful data row.

How do I print a range without opening a dialog?
Calling PrintOut sends the output to Excel’s current printer settings and generally does not require the user to select a printer in a dialog. The default printer and its configuration still matter. Use PrintPreview or a print dialog when a person needs to review the output first.

Does setting PrintArea change the worksheet permanently?
It changes the worksheet’s page setup, and the setting can remain in the workbook. Clear it with ws.PageSetup.PrintArea = "" or save and restore the previous value if the macro only needs a temporary print area.

Can I print a range to PDF with VBA?
Excel’s print-to-PDF workflow depends on the operating system and available printer or export features. For a workbook sheet, the desktop Excel ExportAsFixedFormat method is often a more direct way to create a PDF than sending output to a physical printer; use the method that matches whether you need a saved PDF or printed pages.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.