Print Select worksheets based on cell values

BODYCOTE

New Member
Joined
May 18, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
How would i write the VBA to print worksheets based on the values of column "e" in this table (table60) when i press a button

for example, hit button and current sheet (****tail converter sheet) prints

then

if E4=<0 then print worksheet"b4"! (Amaretto Sour)

and so on until the end of column E (prep)


Thank you in advance

1621334314753.png
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi. Try:

VBA Code:
Sub PrintSomeSheets()
 Dim c As Range, LR As Long
  With ActiveSheet
   On Error Resume Next
   .ShowAllData
   On Error GoTo 0
   .PrintOut
   LR = .Cells(Rows.Count, 5).End(3).Row
   .Range("B3:G" & LR).AutoFilter 4, "<" & 1
   If .AutoFilter.Range.Columns(5).SpecialCells(12).Count > 1 Then
    For Each c In .Range("B4:B" & LR).SpecialCells(12)
     Sheets(c.Value).PrintOut
    Next c
   End If
   .ShowAllData
  End With
End Sub
 
Upvote 0
Solution
Hi. Try:

VBA Code:
Sub PrintSomeSheets()
 Dim c As Range, LR As Long
  With ActiveSheet
   On Error Resume Next
   .ShowAllData
   On Error GoTo 0
   .PrintOut
   LR = .Cells(Rows.Count, 5).End(3).Row
   .Range("B3:G" & LR).AutoFilter 4, "<" & 1
   If .AutoFilter.Range.Columns(5).SpecialCells(12).Count > 1 Then
    For Each c In .Range("B4:B" & LR).SpecialCells(12)
     Sheets(c.Value).PrintOut
    Next c
   End If
   .ShowAllData
  End With
End Sub
Thanks Osvaldo, however, it only printed out sheets with a value of 0 (flying grasshopper, Sex on the beach) instead of greater than 0
 
Upvote 0
Yes, that was my understanding of the criteria to print, based on your statement on post #1 ~~~> "if E4=<0 then print worksheet"b4"! (Amaretto Sour)"
But, to print if E>0 then please, change the criteria from "<" & 1 to ">" & 0
 
Upvote 0
Thanks Osvaldo, however, it only printed out sheets with a value of 0 (flying grasshopper, Sex on the beach) instead of greater

Yes, that was my understanding of the criteria to print, based on your statement on post #1 ~~~> "if E4=<0 then print worksheet"b4"! (Amaretto Sour)"
But, to print if E>0 then please, change the criteria from "<" & 1 to ">" & 0
yes, thankyou. typo on my behalf. do i need to change anything else as the vba will not run now
1621344285437.png
 
Upvote 0
Hey mate,

do you know why i am receiving this error?
 

Attachments

  • Capture.PNG
    Capture.PNG
    61.3 KB · Views: 7
  • Capture.PNG
    Capture.PNG
    56.8 KB · Views: 6
Upvote 0
Hey @Osvaldo Palmeiro,

I recently updated this worksheet to split that table into 2 tables, could you help me to adapt the vba to account for the change? greatly appreciated if you have a moment!!!

VBA Code:
Sub PrintRecipes()
 Dim c As Range, LR As Long, lo As ListObject
 Set lo = Sheets("****tail Conversion Sheet").ListObjects(1)
  With ActiveSheet
   On Error Resume Next
   .ShowAllData
   On Error GoTo 0
   .PrintOut
   LR = .Cells(Rows.Count, 5).End(3).Row
   If Application.CountIf(.Range("E4:E" & LR), ">0") > 0 Then
   .Range("B3:G" & LR).AutoFilter 4, ">" & 0
    For Each c In .Range("B4:B" & LR).SpecialCells(12)
     Sheets(c.Value).PrintOut
    Next c
    lo.AutoFilter.ShowAllData
   End If
  End With
  Sheets("****tail Conversion Sheet").Select
End Sub

The Sheet Looks Like This Now

1642470576885.png
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,732
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top