troubleshooting Question

Printing Debit and Credit using for loop

Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America asked on
Microsoft Excel
1 Comment1 Solution484 ViewsLast Modified:
Hello,
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
next

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
        Next
     
        
    
PROC_EXIT:
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Description, vbCritical, "PopulateData.PopulateLineItems"
    Resume PROC_EXIT
    
End Sub
ASKER CERTIFIED SOLUTION
Juan Velasquez

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros