+ Reply to Thread
Results 1 to 2 of 2

Print Macro or VB code

Hybrid View

  1. #1
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Print Macro or VB code

    See if the attached is what you have in mind. This code is assigned to a button on sheet one. It will hide columns, set the print area and print out, then show all columns and clear the print area.

    Option Explicit
    
    Sub Print_By_Date_Range()
    
        Dim c As Range, strStart As String, strEnd As String, lcol As Long, lrow As Long
        
        strStart = Sheet1.Range("D6").Value
        strEnd = Sheet1.Range("F6").Value
        lcol = Sheet1.Cells(7, Columns.Count).End(xlToLeft).Column
        lrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    
        Application.ScreenUpdating = False
        
        If strStart = vbNullString Or strEnd = vbNullString Then
            MsgBox "Please enter both a start and end date", vbExclamation
            Exit Sub
        End If
        
        On Error Resume Next
        
        For Each c In Range("D7", Cells(7, lcol))
            If c.Value >= strStart And c.Value <= strEnd Then c.EntireColumn.Hidden = True
        Next c
        
        With Sheet1
            .PageSetup.PrintArea = .Range("A7", Cells(lrow, lcol)).Address
            .PrintPreview
            .Columns.Hidden = False
            .PageSetup.PrintArea = ""
        End With
        
        Application.ScreenUpdating = True
        
    End Sub
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1