Avatar of Juan Velasquez
Juan Velasquez
Flag for United States of America asked on

Printing Debit and Credit using for loop

I've written the code below to print the line items in the attached spreadsheet. It works fine and is printing the debit side of the amounts.  I am now trying to print the credit side (basically, mutliplying the Trans Amount by -1).  I'm trying to modify the code so that the credit will be displayed immediatly below the associated debit along with all the other linde data.  I'm thinking that I need to use a for loop such that
For x = 1 to 2
    if x = 1 then
         'Print Debit
          x = x + 1
   elseif x = 2 then
         'Print Credit
         exit for
    end if

I'm just having trouble placing the for loop in the right place.  
Private Sub PopulateLineItems(wsSource As Worksheet, wsDestination As Worksheet)
    ' Comments: Used to populate line items in 8.9 upload report
    ' Params  :
    ' Created : 06/22/12 10:39 JV
    ' Modified:
    On Error GoTo PROC_ERR
    'Populates line items
    Dim rng As Range
    Dim lngY As Long
    Dim dblTransAmount As Double
    Dim rngTran As Range
    Dim strLineId As String
    Dim x As Long
        x = 1
        'Print Debit
        mRngHeaderLine(mlngNextRow, 1).Value = cstLineItem
        mRngCurrencyCode(mlngNextRow, 1).Value = cstCurrencyCode
        mRngLedger(mlngNextRow, 1).Value = cstLedger
        mRngAffiliate(mlngNextRow, 1).Value = Mid(wsSource.Name, 6, 5)
        mRngTransactionId(mlngNextRow, 1).Value = Mid(wsSource.Name, 11, 1)
        Set mRgInterestAccruals = wsSource.Range("InterestAccruals")
        mlngX = 1
        For Each rng In wsSource.Range("MonthEnding")
            If Format(rng, "mmddyyyy") = Format(gstrJournalDate, "mmddyyyy") Then '
                dblTransAmount = CDbl(mRgInterestAccruals(mlngX, 1))
                mRngLineId(mlngNextRow, 14).Value = dblTransAmount
                mRngLineDescription(mlngNextRow, 1) = cstInterest
                Exit For
            End If
            mlngX = mlngX + 1
    Exit Sub
    MsgBox Err.Description, vbCritical, "PopulateData.PopulateLineItems"
    Resume PROC_EXIT
End Sub

Open in new window

Microsoft Excel

Avatar of undefined
Last Comment
Juan Velasquez

8/22/2022 - Mon
Juan Velasquez

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck