Our current system for statement is very manual. It is in an Excel workbook that pulls data from the accounting system. To automate this I have created the following macros:
- TableRefresh.Refresh- This refreshes the Pivot Table (Table 1) on- sheets("Aged Balances")
- Lines.StatementLines- This pulls in the necessary lines for the statement
- PDFEmail.EmailPDF- if- Range("I6")is- Emailthen this attaches the statement to an email as a PDF and sends it
- StatementPrint.PrintStatement- if- Range("I6")is- Emailthen this prints the statement ready for posting
- DB2Clear.ClearDB2- Clears the statement lines ready for the next customers info
Now I am trying to create a macro that pulls those all together. Table 1 (mentioned above) has all the customers, and their Client Codes (Column 1), for which statements need to be created. This is what I have currently:
Sub Statements()
    Dim i As Integer
    Dim LastRow As Long
    With Sheets("Aged Balances")
        LastRow = .Cells(.Rows.Count, 14).End(xlUp).Row
    End With
    Call TableRefresh.Refresh
    'Now the loop begins.
    For i = 3 To LastRow
    'Now set the new Client Code
    Worksheets("Statement").Range("K3").Value = Worksheets("Aged 
    Balances").Cells(i, 1).Value
    Call Lines.StatementLines
        If Sheets("Statements").Range("I6").Value = "Email" Then
            Call PDFEmail.EmailPDF
        ElseIf Sheets("Statements").Range("I6").Value = "Print" Then
            Call StatementPrint.PrintStatement
        Else
            Return
        End If
        MsgBox "Statement Complete", vbInformation
        Call DB2Clear.ClearDB2
    Next i
    MsgBox "Statements Complete", vbInformation    
End Sub
When using the F8 step through method I noticed that it gets to the first line of the loop section(For i = 3 To LastRow) then completely skips the whole loop section and goes to the Message Box.
Thanks in advance for your help and advice on this. Most appreciated.
 
    