Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Printing worksheets from a macro

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    449
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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

  2. #2
    MrExcel MVP Barrie Davidson's Avatar
    Join Date
    Feb 2002
    Location
    Winnipeg
    Posts
    2,330
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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:


    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


    Regards,
    Barrie Davidson

    "You're only given a little spark of madness. You mustn't lose it." - Robin Williams

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •