Print Excel Recipe Sheets Marked YES with a VBA Macro
Question details
Print each recipe worksheet whose corresponding row on the INDEX sheet is marked YES.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- An INDEX sheet lists menu names in column C and YES or NO selections in column F. Some recipe worksheet names differ from the menu names.
- Observed behavior
- The user needs a macro that identifies YES rows and prints the matching recipe worksheets using their actual sheet names.
Check that the INDEX sheet has headers in row 1 and YES or NO values in column F. If column C contains menu names rather than exact worksheet tab names, add the corresponding worksheet names in column G.
Run a VBA macro to print the selected recipe worksheets
Use this macro to read YES selections from column F and print the worksheet named on each selected row.
The macro uses column C for worksheet names by default. If the menu names differ from the worksheet tabs, put the exact tab names in column G and change the sheetNameCol value from "C" to "G".
Each YES row is printed separately. A message identifies selected rows whose worksheet names are blank or do not match a worksheet.
Open the workbook in desktop Excel, press Alt+F11 to open the VBA editor, and select Insert > Module. Paste the following code into the module: Sub PrintSelectedRecipes() Dim indexSheet As Worksheet Dim recipeSheet As Worksheet Dim lastRow As Long, r As Long Dim sheetName As String, missing As String Dim selectedCount As Long Const sheetNameCol As String = "C" Set indexSheet = ThisWorkbook.Worksheets("INDEX") lastRow = indexSheet.Cells(indexSheet.Rows.Count, "F").End(xlUp).Row For r = 2 To lastRow If UCase(Trim(CStr(indexSheet.Cells(r, "F").Value))) = "YES" Then selectedCount = selectedCount + 1 sheetName = Trim(CStr(indexSheet.Cells(r, sheetNameCol).Value)) Set recipeSheet = Nothing On Error Resume Next Set recipeSheet = ThisWorkbook.Worksheets(sheetName) On Error GoTo 0 If recipeSheet Is Nothing Then missing = missing & vbCrLf & "Row " & r & ": " & sheetName Else recipeSheet.PrintOut End If End If Next r If selectedCount = 0 Then MsgBox "No rows are marked YES." If Len(missing) > 0 Then MsgBox "No worksheet found for:" & missing End Sub
In the VBA editor, leave Const sheetNameCol As String = "C" if column C contains the exact worksheet names. Otherwise, enter the actual names in column G on INDEX and change "C" to "G" in that line.
Use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Enable macros if prompted and you trust the workbook, then open Developer > Macros, select PrintSelectedRecipes, and click Run.
If the macro reports missing worksheets, check the listed rows on INDEX against the worksheet tabs. Correct the names in the configured column, then run the macro again.

Work with recipe workbooks in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Excel format compatibility, making it easy to move recipe workbooks between office suites. You can review and print recipe sheets in WPS Spreadsheets; the Excel VBA macro above is an Excel-specific solution.

Frequently Asked Questions
What if the menu name is different from the worksheet name?
Add the exact worksheet tab name to column G on the same INDEX row, then change the macro's sheetNameCol constant from "C" to "G".
Do I need to replace PrintOut with each actual sheet name?
No. The macro reads the sheet name from the configured INDEX column and assigns that worksheet to recipeSheet before calling recipeSheet.PrintOut.
What happens if no rows are marked YES?
The macro displays a message saying that no rows are marked YES and does not print any worksheets.
How do I keep the macro in the workbook?
In Excel, choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm). Enable macros when prompted only if you trust the workbook and its code.




