Calculate sum as per record type

Here is my sample excel file data

How can I calculate sum of all CR and DR type records separately? Result should be

Total Debit = XXX Total Credit = XXX

Logic somthing like...

Dim debit;
for each row in sheet1
    if(data of C column == dr)
        debit = debit + data of D column
    end if
end for
print debit; 

I am not very much familiar with Excel 2010 so not sure how to code this so please give me some basic steps also to achieve this.

Answers


You can get this using formula :

   =SUMIF(C:C,"=DR",D:D)

And if you want to get this using vba then you can write it like:

Dim debit, credit As Integer

With Worksheets("Sheet1")

    For x = 1 To .Cells(Rows.Count, 3).End(xlUp).Row

        If UCase(.Cells(x, 3).Value) = "DR" Then
            debit = debit + .Cells(x, 4).Value
        Else
            If UCase(.Cells(x, 3).Value) = "CR" Then
                credit = credit + .Cells(x, 4).Value
            End If
        End If
    Next

End With

Need Your Help

JQuery Tooltip Not Allowing Button to be Clicked

javascript jquery html css

I'm using JQuery tooltip plugin and I'm trying to simulate a input button on hover, which it does successfully but I cannot click on said button. It's like it never exists in the DOM, or maybe it d...

Organising complicated Django models

database django django-models

I'm currently building an app for a client where each record has a large number of different pieces of information (around 50-60 fields) associated with it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.