Printing worksheets from a macro

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
I have 2 columns "a" and "b"
in "a" they are either 0 or 1
in b are the worksheets I want to print ie Sheet2 Sheet3

I need a macro that goes down column a till it finds a 1 then goes to column b and prints out that worksheet and then returns and carries on untill it finds another 1 and prints the next one
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
On 2002-03-11 06:59, nehpets12 wrote:
I have 2 columns "a" and "b"
in "a" they are either 0 or 1
in b are the worksheets I want to print ie Sheet2 Sheet3

I need a macro that goes down column a till it finds a 1 then goes to column b and prints out that worksheet and then returns and carries on untill it finds another 1 and prints the next one

Here you go:

<pre>
Sub PrintOut()
' Written by Barrie Davidson
Dim SheetToPrint As String

'Go to the error handling routine
'if an error is encountered
On Error GoTo ErrorMessage

'Turn off the screen
Application.ScreenUpdating = False

'Start at A1
Range("A1").Select

'Do this loop until the there is nothing
'in the selected cell
Do Until Selection.Value = ""
If Selection.Value = 1 Then 'if the selected cell = 1
SheetToPrint = Selection.Offset(0, 1).Value 'get the sheet name to print
Sheets(SheetToPrint).PrintOut 'print that sheet
End If
Selection.Offset(1, 0).Select 'go the next cell
Loop

'Turn the screen on
Application.ScreenUpdating = True
Exit Sub

'Error handling routine
ErrorMessage:
MsgBox prompt:="Macro error, contact macro author"
Application.ScreenUpdating = True
End Sub
</pre>

Regards,
 
Upvote 0

Forum statistics

Threads
1,214,384
Messages
6,119,201
Members
448,874
Latest member
Lancelots

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