# Excel Macro for printing certain sheets in a workbook



## shawnb18 (Feb 25, 2008)

I need help in creating a macro that will print every sheet in my workbook that has a value placed in cell B11. The sheet the macro would be on is called "payrollinfp" and all of the other sheets in the workbook are, "Sales Invoice", "Sales Invoice2", etc... all the way to "Sales Invoice20"

I have a basic print macro I recorded but I can't seem to figure out how to code an if statement into it so it prints only those certain sheets.

Thank you!


----------



## Glaswegian (Sep 16, 2005)

Hi 

Perhaps something like this?

```
Sub Test5()
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
   If sht.Range("B11").Value <> "" Then
        sht.PrintOut
    End If
Next sht

End Sub
```


----------



## shawnb18 (Feb 25, 2008)

That works great! Thank you!!!!


----------



## djrhodes (Oct 28, 2009)

I also need to print certain sheets. But I need to print only the sheets that have the dollar amount more than $5.00. What code do I need to put for that?

Thanks!!!


----------



## Glaswegian (Sep 16, 2005)

Hi and welcome.

Just a small change should do it...

```
Sub Test5()
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
   If sht.Range("B11").Value > 5 Then
        sht.PrintOut
    End If
Next sht

End Sub
```


----------



## SumIF (Nov 18, 2010)

Thanks this is just what I need, I have created a set of checkboxes that are linked to a cell in a worksheet and triger values: TRUE or FALSE. I tried to use this code by changing a couple of things as follows:

```
Sub Test5()
Dim sht As Worksheet 
 
For Each sht In ThisWorkbook.Worksheets 
If sht.Range("B11").Value = "TRUE" Then sht.PrintOut 
 
End If
Next sht
 
End Sub
```
Saved the code under the worksheet in excel, tried to link the button to that code, but it DOESN't work  Am I doing something wrong?


----------



## Glaswegian (Sep 16, 2005)

Hi and welcome.

What type of button did you use? Are you calling the correct sub from your button?

Can you provide a bit more detail?


----------

