+ Reply to Thread
Results 1 to 8 of 8

Macro to Print Update and Print Sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Macro to Print Update and Print Sheet

    I have a workbook where 1 sheet has a list of numbers starting at b12 on down (list gets bigger and smaller) and another sheet has a bunch of lookup formulas on it. I key in the numbers 1 by 1 from the 1st sheet into cell N1 on the sheet with the formulas. The formulas then input a bunch of info creating an invoice and I print the page. Then key the next number and so on.

    Is it possible to have a macro enter the numbers for me 1 by 1 printing each page after it enters?? This would be a tremendous time saver.

    Thank you very much for your time and help.
    Last edited by erock24; 11-21-2007 at 06:59 PM.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi there,

    Let me know if the following does the trick - just change the reference to Sheet1 to the tab name where the invoice number(s) are listed and the references to Sheet2 to the invoice tab.

    HTH

    Robert

    Sub PrintAllInvs()
    
    Sheets("Sheet1").Select
    Range("B12").Select
    
    Do Until IsEmpty(ActiveCell) = True
    ActiveCell.Copy Sheets("Sheet2").Range("N1")
    Sheets("Sheet2").PrintOut
    ActiveCell.Offset(1, 0).Select
    Loop
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    I tested it but a different way. Turns out I need to be able to print sometimes and other times just keep copies as different sheet tabs.

    So, I set this up but... it only did the first one and stopped. Seems that the offset command affected cell n1 on the invoice sheet because cell n2 was the active cell on that page when the macro stopped. I don't know how to get the offset to work on the "CL lookup" page in the desired range (b12:down) Any Ideas???

    Sub PrintAllInvs()
    
    Sheets("CL lookup").Select
    Range("B12").Select
    
    Do Until IsEmpty(ActiveCell) = True
    ActiveCell.Copy Sheets("Invoice").Range("N1")
    Sheets("Invoice").Copy Before:=Sheets(5)
    Sheets("Invoice (2)").Name = Range("I14").Value
    'Sheets("Sheet2").PrintOut
    ActiveCell.Offset(1, 0).Select
    Loop
    
    End Sub
    This is 2nd priority, but it would be nice to somehow choose if I want to just print or If I want to have an active copy of each invoice. And if it is doable, if I choose active copy, then maybe an option at end to print active invoices.

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi there,

    As I don't have any data, I've created the following code based on the assumption that the new (active) invoice tabs are the unique invoice numbers (i.e. the value in cell I14 of the Invoice tab) and put either a "C" (for create) or "P" (for print) flag next to the invoice numbers (Column C) in the "CL lookup" tab.

    Sub PrintAllInvs()
    
    Application.ScreenUpdating = False
    
    Dim lngRowNo As Long
    Dim strActiveInv As String
    lngRowNo = 12
    
    Sheets("CL lookup").Select
    Range("B" & lngRowNo).Select
    
    Do Until IsEmpty(ActiveCell) = True
    
        If StrConv(Range("C" & lngRowNo), vbUpperCase) = "C" Then
        
        ActiveCell.Copy Sheets("Invoice").Range("N1")
        Sheets("Invoice").Copy after:=Worksheets(Worksheets.Count)
        ActiveSheet.Name = Range("I14").Value
        Sheets("CL lookup").Select
        lngRowNo = lngRowNo + 1
        Range("B" & lngRowNo).Select
        
        Else
        
        ActiveCell.Copy Sheets("Invoice").Range("N1")
        Sheets("Invoice").PrintOut
        lngRowNo = lngRowNo + 1
        Range("B" & lngRowNo).Select
        
        End If
        
    Loop
    
        If MsgBox("Would you like to print all the active invoices?", vbYesNo + vbInformation, "Print Active Invoices Editor") = vbYes Then
        
        lngRowNo = 12
        Sheets("CL lookup").Select
        Range("C" & lngRowNo).Select
        
        Do Until IsEmpty(ActiveCell) = True
        
            If StrConv(Range("C" & lngRowNo), vbUpperCase) = "C" Then
            strActiveInv = Range("B" & lngRowNo)
            Sheets(strActiveInv).PrintOut
            End If
            lngRowNo = lngRowNo + 1
        
        Loop
    
        End If
    
    Application.ScreenUpdating = True
    
    End Sub
    To be honest (in my opinion) I'd actually do this in Access as there will invariably be issues with the number of sheet tabs, duplicate tab names, tab ordering and processing time as the number of invoices grow, which though mostly can be overcome with additional code, unnecessarily complicates matters.

    HTH

    Robert
    Last edited by Trebor76; 11-22-2007 at 06:54 PM.

  5. #5
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299
    Thank you very much for your help and advice.

    I tested code and,
    One weird thing is that I tested it with only having "C"s and it created them, then asked to print, when I hit yes to print it printed them fine, but also errored out highlighting this:
    If StrConv(Range("N" & lngRowNo), vbUpperCase) = "C" Then
    The only other issue with the code is when I only have "P", I then don't need the second part to run.
    But it still works and is a time saver.

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi there,

    It's hard to fully test without actual data, but see if this meets all your needs.

    Regards,

    Robert

    Sub PrintAllInvs()
    
    Application.ScreenUpdating = False
    
    Dim lngRowNo As Long
    Dim intPrintCounter As Integer
    Dim strActiveInv As String
    
    lngRowNo = 12
    intPrintCounter = 0
    
    Sheets("CL lookup").Select
    Range("B" & lngRowNo).Select
    
    Do Until IsEmpty(ActiveCell) = True
    
        If StrConv(Range("C" & lngRowNo), vbUpperCase) = "C" Then
              
        ActiveCell.Copy Sheets("Invoice").Range("N1")
               
        Sheets("Invoice").Copy after:=Worksheets(Worksheets.Count)
        ActiveSheet.Name = Range("I14").Value
        Sheets("CL lookup").Select
        lngRowNo = lngRowNo + 1
        Range("C" & lngRowNo).Select
        
        Else
        
        ActiveCell.Copy Sheets("Invoice").Range("N1")
        Sheets("Invoice").PrintOut
        intPrintCounter = intPrintCounter + 1
        lngRowNo = lngRowNo + 1
        Range("B" & lngRowNo).Select
        
        End If
        
    Loop
    
        If intPrintCounter = 0 Then Exit Sub
        
        If MsgBox("Would you like to print all the invoices?", vbYesNo + vbInformation, "Print Active Invoices Editor") = vbYes Then
        
        lngRowNo = 12
        Sheets("CL lookup").Select
        Range("B" & lngRowNo).Select
        
        Do Until IsEmpty(Range("B" & lngRowNo)) = True
        
            strActiveInv = Range("B" & lngRowNo)
            Sheets(strActiveInv).PrintOut
            lngRowNo = lngRowNo + 1
        
        Loop
    
        End If
        
    Application.ScreenUpdating = True
    
    End Sub

+ 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