Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Only print worksheets with data in B2

Office 2003
I have created a workbook template with 31 worksheets and a main worksheet,
I would like to press a command button from the main worksheet that will
loop through all 31 sheets and send to the printer all sheets with data in
the B2 cell.

thanks in advance, David


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Only print worksheets with data in B2

Why not put all the values on 1 sheet and print that
sheet? Try a macro like this:

Sub AllB2()
Dim ws As Worksheet
Dim i As Long
Dim iLastRow As Long

Set ws = Worksheets.Add(befo=Worksheets(1))

With ws
For i = 2 To ActiveWorkbook.Worksheets.Count
If Worksheets(i).[B2].Value < "" Then
.Cells(iLastRow + 1, "A").Value = _
Worksheets(i).Name
.Cells(iLastRow + 1, "B").Value = _
Worksheets(i).[B2]
End If
iLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
Next
.Cells(1, "A").Value = "Sheet Names"
.Cells(1, "B").Value = "Value in B2"
End With

Range("A:B").EntireColumn.AutoFit

ws.PrintOut Copies:=1, Collate:=True

End Sub

---
To run, press ALT+F11, go to Insert Module, and paste
in the code. Press ALT+Q to close VBE and run the macro
under Tools Macro.

HTH
Jason
Atlanta, GA


-----Original Message-----
Office 2003
I have created a workbook template with 31 worksheets

and a main worksheet,
I would like to press a command button from the main

worksheet that will
loop through all 31 sheets and send to the printer all

sheets with data in
the B2 cell.

thanks in advance, David


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Only print worksheets with data in B2

David,

If the main workhsheet has cell B2 blank, then:

Sub PrintSheets()
Dim Wks As Worksheet

For Each Wks In ActiveWorkbook.Worksheets
If Wks.Range("B2").Value < "" Then Wks.PrintOut
Next Wks
End Sub

HTH,
Bernie
MS Excel MVP

"David D" wrote in message
...
Office 2003
I have created a workbook template with 31 worksheets and a main

worksheet,
I would like to press a command button from the main worksheet that will
loop through all 31 sheets and send to the printer all sheets with data in
the B2 cell.

thanks in advance, David




  #4   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Only print worksheets with data in B2

This was tested


Sub printb2()
For Each w In ThisWorkbook.Sheets
If w.Range("b2") < "" Then w.PrintOut Copies:=1
Next
End Sub


"David D" wrote:

Office 2003
I have created a workbook template with 31 worksheets and a main worksheet,
I would like to press a command button from the main worksheet that will
loop through all 31 sheets and send to the printer all sheets with data in
the B2 cell.

thanks in advance, David



  #5   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Only print worksheets with data in B2

copies:=1 should be on the same line as printout
sorry


"ben" wrote:

This was tested


Sub printb2()
For Each w In ThisWorkbook.Sheets
If w.Range("b2") < "" Then w.PrintOut Copies:=1
Next
End Sub


"David D" wrote:

Office 2003
I have created a workbook template with 31 worksheets and a main worksheet,
I would like to press a command button from the main worksheet that will
loop through all 31 sheets and send to the printer all sheets with data in
the B2 cell.

thanks in advance, David





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Certain worksheets won't print Larry_thornton Excel Discussion (Misc queries) 1 December 6th 09 04:02 PM
Need to print a workbook but worksheets have diff print areas Angela Steele Excel Discussion (Misc queries) 1 January 17th 08 07:39 PM
How do I print a workbook in but only print selected worksheets? Karl S. Excel Discussion (Misc queries) 1 August 31st 06 12:34 AM
Pivot Table macro to set print area and print details of drill down data Steve Haskins Excel Discussion (Misc queries) 2 December 28th 05 04:59 PM
print out of worksheets Ankur Excel Worksheet Functions 3 August 11th 05 01:12 PM


All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"