Excel VBA Macro to Print or Export Sheets from Recap Values
Question details
Create a VBA macro that uses values from the Recap sheet to print or export a worksheet for each value.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A user wants to place each sequential value from Recap column B into cell G11 of an output worksheet and produce a separate result.
- Observed behavior
- Each populated value should generate a printed worksheet, a PDF, or both.
Confirm that the source values are in Recap column B and identify the first data row, output worksheet name, and destination cell. Check the output worksheet's print area and page layout before running the macro.
Loop through Recap values and print or export the worksheet
Use this macro to process each populated row in Recap column B, with switches for printing and PDF export.
In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). If exporting PDFs, save the workbook in a local folder first.
Open the workbook, select Developer > Visual Basic, and then select Insert > Module. On Windows, Alt+F11 also opens the VBA editor.
Paste this code into the module: Sub PrintOrExportRecapValues() Const FIRST_ROW As Long = 2 Const DO_PRINT As Boolean = True Const DO_PDF As Boolean = False Dim recap As Worksheet Dim outputSheet As Worksheet Dim lastRow As Long Dim r As Long Dim pdfPath As String Set recap = ThisWorkbook.Worksheets("Recap") Set outputSheet = ThisWorkbook.Worksheets("Worksheet") If DO_PDF And Len(ThisWorkbook.Path) = 0 Then MsgBox "Save the workbook in a local folder before exporting PDFs." Exit Sub End If lastRow = recap.Cells(recap.Rows.Count, "B").End(xlUp).Row For r = FIRST_ROW To lastRow If Len(Trim$(CStr(recap.Cells(r, "B").Value))) > 0 Then outputSheet.Range("G11").Value = recap.Cells(r, "B").Value Application.Calculate If DO_PRINT Then outputSheet.PrintOut If DO_PDF Then pdfPath = ThisWorkbook.Path & Application.PathSeparator & "Output_" & r & ".pdf" outputSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath End If End If Next r End Sub
In the code, change FIRST_ROW, the worksheet names, or G11 as needed. Set DO_PDF to True to create PDFs and DO_PRINT to False if you only want PDFs. Return to Excel, select Developer > Macros, choose PrintOrExportRecapValues, and select Run.

Work with Recap spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface for moving everyday workbook tasks from Microsoft Office. VBA support varies by WPS edition and installation, so verify macro compatibility before relying on the Excel code.

Frequently Asked Questions
How do I export PDFs without printing?
In the VBA module, set DO_PRINT to False and DO_PDF to True. Save the workbook in a local folder before running the macro.
Where are the PDF files saved?
The macro saves them in the workbook's folder using names such as Output_2.pdf. Change the pdfPath assignment if you need another destination.
Can I start with a row other than row 2?
Yes. Change the FIRST_ROW constant in the VBA module to the first row containing a value to process.
What if my output sheet has a different name or input cell?
Replace "Worksheet" in the Worksheets reference with the actual sheet tab name, and replace "G11" in the Range reference with the desired input cell.
Why do the printed pages not fit as expected?
Select the output sheet and check Page Layout > Print Area and Page Layout > Scale to Fit before running the macro. The macro uses the worksheet's existing print settings.




