# Message box depending on the sum

#### kbp

##### New Member
Hi

This is a bit complex for me. I am trying to do a VBA on an excel data sheet. On this data sheet, in column E there are amounts and in column F there is either "C" (for Credit) or "D" (for debit) against the amount. So if you see the below example I have copies, 50000 D is for debit.

What I want to do is, add all the amounts against the C and all the amounts against the D, then pop up a message box to say, if debit = credit matches or does not match. The tricky part is everyday we have different amounts with different number of rows. So someday it can be 100 rows whereas someday it can be 1500 rows.

Is someone able to help me please. Thank you.

Col E Col F

 50000 D 4500 D 94500 C 20000 D 40000 D 75000 D 80000 D 127500 D 342500 C 50000 D 50000 C 8010 C 2685 C 80000 C 40000 C

<tbody>
</tbody>

<tbody>
</tbody>

### Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Maybe this.
Will do from e1 down to as far as there is data

Code:
``````Sub MM1()
Dim lr As Long, c As Double, d As Double
lr = Cells(Rows.Count, "E").End(xlUp).Row
c = Application.WorksheetFunction.SumIf(Range("F1:F" & lr), "C", Range("E1:E" & lr))
d = Application.WorksheetFunction.SumIf(Range("F1:F" & lr), "D", Range("E1:E" & lr))
If c <> d Then
MsgBox "Credit of " & c & " does not equal Debit of " & d
ElseIf c = d Then
MsgBox "Credit " & c & " equals Debit " & d
End If
End Sub``````

Awesome, thanks very much Michael.

Pleasure...

Replies
10
Views
273
Replies
5
Views
93
Replies
10
Views
563
Replies
3
Views
277
Replies
3
Views
149

1,207,013
Messages
6,076,151
Members
446,187
Latest member
LMill

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back