Excel Formula/VBA-Conditional Sum to find contra from multiple entries

Miratshah

Board Regular
Joined
Nov 29, 2016
Messages
57
Hi Experts,

I have a sheet which runs into over 30000 rows. I need to find contra entries within a company in column B for a each job in column C. Basically I need to find which transactions sum to 0 in column K (Balance in Base). so for example, in company code IN9073 in column B, there are 30 transactions which sum to 3,000 in column K (Balance in base). I have manually identified whether in each transaction is contra on not in column L (Marker2). If a particular transaction is not summing to 0, I have marked it as WIP.

The problem is there can be transaction with amount + and - which can be identified AND transactions where different amounts with different signs sum to 0.

I need this to be achieved by way of some formula or VBA. I tried sumifs but failed when there are 10 transactions out of which 8 are contra and 2 are not.

The HTML of my excel is below,

P.s. Rounding off to 1 or 2 is completely allowed :-)

Thanks in advance.



Book1
ABCDEFGHIJKL
1Company No.Company CodeJob No.Account No.Trans. No.Journal No.Date PostedEntry DateDebitsCreditsBalance in BaseManual
58110IN9073110695711600511012100111014223830/11/201030/11/20101,000.000.001,000CONTRA
59110IN9073110695711600511012100111014223830/11/201030/11/20102,000.000.002,000CONTRA
60110IN9073110695711600511015472411013261731/03/201029/03/20100.0038,500.00-38,500CONTRA
61110IN9073110695711600511076457711013045308/02/201008/02/20101,000.000.001,000CONTRA
62110IN9073110695711600511076458511013046208/02/201008/02/20101,000.000.001,000CONTRA
63110IN9073110695711600511076461611013049408/02/201008/02/20101,000.000.001,000CONTRA
64110IN9073110695711600511076464011013052408/02/201008/02/20101,000.000.001,000CONTRA
65110IN9073110695711600511076468511013057809/02/201009/02/20101,000.000.001,000CONTRA
66110IN9073110695711600511076472011013062710/02/201010/02/20101,000.000.001,000CONTRA
67110IN9073110695711600511076490511013104322/02/201022/02/20101,000.000.001,000CONTRA
68110IN9073110695711600511076491011013105722/02/201022/02/201012,500.000.0012,500CONTRA
69110IN9073110695711600511076511911013157805/03/201005/03/20101,000.000.001,000CONTRA
70110IN9073110695711600511076523211013179413/03/201013/03/20101,000.000.001,000CONTRA
71110IN9073110695711600511076528811013185013/03/201013/03/20102,000.000.002,000CONTRA
72110IN9073110695711600511076529211013185413/03/201013/03/20103,000.000.003,000CONTRA
73110IN9073110695711600511076529411013185613/03/201013/03/20101,000.000.001,000CONTRA
74110IN9073110695711600511076530911013187113/03/201013/03/20101,000.000.001,000CONTRA
75110IN9073110695711600511076532011013188213/03/201013/03/20101,000.000.001,000CONTRA
76110IN9073110695711600511076534011013190213/03/201013/03/20101,000.000.001,000CONTRA
77110IN9073110695711600511076535511013191715/03/201015/03/20101,000.000.001,000CONTRA
78110IN9073110695711600511076539111013200516/03/201016/03/20101,000.000.001,000CONTRA
79110IN9073110695711600511076554311013229023/03/201023/03/20102,000.000.002,000CONTRA
80110IN9073110695711600511076554411013229123/03/201023/03/20102,000.000.002,000CONTRA
81110IN9073110695711600511076554611013229323/03/201023/03/20102,000.000.002,000CONTRA
82110IN9073110695711600511076640111013445121/05/201021/05/20100.001,000.00-1,000CONTRA
83110IN9073110695711600511076640211013445221/05/201021/05/20100.001,000.00-1,000CONTRA
84110IN9073110695711600511076640311013445421/05/201021/05/20100.001,000.00-1,000CONTRA
85110IN9073110695711603011071968411014101530/10/201028/10/20101,000.000.001,000WIP
86110IN9073110695711603011071968611014101530/10/201028/10/20101,000.000.001,000WIP
87110IN9073110695711603011071968811014101530/10/201028/10/20101,000.000.001,000WIP
Sheet1
 
Last edited:
Hey Akuini,

While the code works absolutely brilliant, when I add a big volume, I get an error saying "Error found:Overflow"

Any idea?

Could you be more specific with what you mean by a big volume?


Try replacing all "Integer" with "Long" in this part:

Sub CombinationsNP2(vElements As Variant, p As Integer, vresult As Variant, lRow As Long, iElement As Integer, iIndex As Integer)
Dim i As Integer


so it becomes:

Sub CombinationsNP2(vElements As Variant, p As Long, vresult As Variant, lRow As Long, iElement As Long, iIndex As Long)
Dim i As Long
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Could you be more specific with what you mean by a big volume?

When I tried to run this macro on rows about 60000 rows, It ran once and in next few runs, I got an error of Overflow.

I will try to replace "integer" with "long" as per your suggestion.
 
Upvote 0
Hi Akuini,

I tried to replace Integer with Long, however still no luck.
Strangely I could execute the old Macro on huge data. Not sure why sometimes it does not run and five overflow error.

One more thing, for 1 job, there can be multiple combinations which are marked as contra. Can this Macro highlight which all combinations are contra with each other? For example, if I have 500 lines of which, 300 are contra, Can i know within these 300, which rows are contra against which rows?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

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

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

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
Back
Top