Consulting

Results 1 to 7 of 7

Thread: Macro to Print Worksheets Containing Specific Data

  1. #1

    Macro to Print Worksheets Containing Specific Data

    Good Morning -

    I have been watching youtube videos and reading blogs for 2 days now. I am trying to figure out the code that will allow my users to select a print button that will only print to PDF the worksheets in the file that have the word print in any cell in columns T & U. Is this possible?

  2. #2
    Do you know how to print to PDF?
    Sub Select_With_Print()
    Dim ws As Worksheet
        For Each ws In ActiveWorkbook.Worksheets
            With ws
                If WorksheetFunction.CountIf(.Range("T:U"), "print") <> 0 Then ws.Select False
            End With
        Next ws
    End Sub
    This should save the sheets as individual pdf files in the folder that houses your excel workbook.
    Sub Or_Maybe()
    Dim i As Long, ws As Worksheet
    For i = 1 To ActiveWorkbook.Worksheets.Count
            With Sheets(i)
                If WorksheetFunction.CountIf(.Range("T:U"), "print") <> 0 Then Sheets(i).ExportAsFixedFormat Type:=xlTypePDF, _
                Filename:=ThisWorkbook.Path & "\" & Sheets(i).Name, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
            End With
    Next i
    End Sub
    Last edited by jolivanes; 11-29-2017 at 07:38 PM. Reason: more info

  3. #3
    Thank you! I was able to get this to 1/2 work. I can get it to select the sheets with "print" in T or U however, nothing actually prints. Also, can I set it up to print to 1 PDF file rather then 1 file for each worksheet?

  4. #4
    The top code does not print, hence the question if you know how to print to PDF.
    I'll look into it a little later.

  5. #5
    Kristy
    Does this do what you have in mind?
    Sub AAAAA()
    Dim cntr As Long, shArr(), ws As Worksheet
    cntr = 0
    
    
        For Each ws In ActiveWorkbook.Worksheets
            If WorksheetFunction.CountIf(ws.Range("C:D"), "print") <> 0 Then
                ReDim Preserve shArr(cntr)
                    shArr(cntr) = ws.Name
                cntr = cntr + 1
            End If
        Next ws
        
    Sheets(shArr).Select
    
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & "All_Together" & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=True
    
    
    End Sub

  6. #6

    THANK YOU!!!!

    IT WORKED!!!!!!!! Thank you so much!




    Quote Originally Posted by jolivanes View Post
    Kristy
    Does this do what you have in mind?
    Sub AAAAA()
    Dim cntr As Long, shArr(), ws As Worksheet
    cntr = 0
    
    
        For Each ws In ActiveWorkbook.Worksheets
            If WorksheetFunction.CountIf(ws.Range("C:D"), "print") <> 0 Then
                ReDim Preserve shArr(cntr)
                    shArr(cntr) = ws.Name
                cntr = cntr + 1
            End If
        Next ws
        
    Sheets(shArr).Select
    
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & "All_Together" & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=True
    
    
    End Sub

  7. #7
    Thank you for letting us know.
    I like your enthusiasm.
    Good luck

Posting Permissions

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