vba help - loop is very slow for record 70000

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I have 70000 records I have to loop/Filter and update Responsibility and Remarks Columns.
By Checking all conditions. First two conditions are Reasons and Actionable if met
then check all notional Columns as per Conditions givens. IF Condition fulfilled I have to update Responsility and Remarks Columns.

in all Notional amounts there are formulas also there in actual Project... but it contain all notionals value either 0,>0, or <0.

In condition Criteria there are 9 criteria are added at the moment, But in actual there are 25 Conditions to check.

Every single conditions at least 4 to 6 columns cells to check.

Which method is best loop is very slow.... can we create dynamic Autofilter function here



Below is the Sample data ....Colum J and K to be fill. J and K Already filled . as per Criteria.

Book3
ABCDEFGHIJKLM
1Sr NoOutstanding BalanceBalance as per sapUnallocated PaymentUnadjusted ClaimQtyClaim AmountQVPVResponsibilityRemarkReasonsActionables
2100100100100100100100ABC CompanyClearedCollection ClearedFully allocated
3100100100100100100100ABC CompanyClearedCollection ClearedFully allocated
4225075100100100100100100 PQTo write OffCollection ClearedTo be Write Off
52-250-100100100100100100100 PQTo write OffCollection ClearedTo be Write Off
630300100100100100100100ABC CompanyClearedCollection ClearedExcess Payment
7410003001000111700100333111CFAPOD Required- Mismatch in QuantityPrice, Qty, Claims DifferenceCheck with CFA for the Qty Mismatch
851000100010002221000300111444RBPrice IssuePrice, Qty, Claims DifferenceCheck with RB for PV Cases
961000100010005001000300333444RBUnadjusted claimsPrice, Qty, Claims DifferenceCheck with RB for PV Cases
1071000100010002001002005060RBWritten off to Misc GLPrice, Qty, Claims DifferenceCN to be Raised
1182500100010001000100010001000ABC CompanyClearedCollection ClearedWritten off to Misc GL
128-2500100010001000100010001000ABC CompanyClearedCollection ClearedWritten off to Misc GL
13900100010001000100010001000ABC CompanyClearedComplete ReversalFully allocated
14900100010001000100010001000ABC CompanyClearedComplete ReversalFully allocated
15105000500100010001000100010001000CustomerIn query with CustomerIn QueryCheck with Customer for details
Sheet2




Criteria to Check Responsibility and Remarks are .... Only 9 Criteria like that there are 24 Criteria.
Looking best way to handle with.......... First Two Criteria are Reasons and Actionable if met Check Conditions.


Debtors Macro Remark Condition (007).xlsx
ABCDE
1ReasonsActionablesConditionResponsibilityRemark
2Collection ClearedFully allocatedO/s Balance and Bal as per SAP should be zeroABC CompanyCleared
3Collection ClearedTo be Write OffO/s Balance and bal as per SAP as on Amount should be between + or – 250 PQTo write Off
4Collection ClearedExcess PaymentO/s Balance should be 0 and unallocated payment amount is greater than 0ABC CompanyCleared
5Price, Qty, Claims DifferenceCheck with CFA for the Qty MismatchQty Dispute is non zero, QV is greater thanPV and Unadjusted ClaimCFAPOD Required- Mismatch in Quantity
6Price, Qty, Claims DifferenceCheck with RB for PPV CasesPV is non zero, PV is greater than QV and Unadjusted ClaimRBPrice Issue
7Price, Qty, Claims DifferenceCN to be RaisedUnadjusted claims is non zero and it is greater than PV and QVRBUnadjusted claims
8Collection ClearedWritten off to Misc GLO/s Balance Amount should be between + or – 250 and bal as per SAP as on amount is ZeroRBWritten off to Misc GL
9Complete ReversalFully allocatedO/s Balance and Bal as per SAP should be zeroABC CompanyCleared
10In QueryCheck with Customer for detailsO/s Balance and Bal as per SAP should be non zeroPrice, Qty, Claims DifferenceCN to be Raised
Criteria




Thanks
mg
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try this code, it will very fast to run because I have loaded all the data into a variant array ( Alldata) and I am writing out to a varaint array ( outarr) . The condition for 5 ,6 and 7 I couldn't do because the data wasn't there in your example , but you see how it can easily be added. Also in your rule 2 , "O/s Balance and bal as per SAP as on Amount should be between + or – 250" however your test data has value of 250 in B4 and -250 in B5 , so both of these FAIL this test because they are not BETWEEN -250 and 250. I have added >= and =< to the equations on rule 2 to check it works correctly. ( But Not on rule 8)
You choose which you want.
VBA Code:
Sub test()
With Worksheets("Criteria")
 crit = Range(.Cells(1, 1), .Cells(10, 6))
End With
With Worksheets("Sheet2")
 lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
 alldata = Range(.Cells(1, 1), .Cells(lastrow, 13))
 outarr = Range(.Cells(1, 10), .Cells(lastrow, 11))
 For i = 2 To lastrow
  ' loop through criteria
  updateRR = False
  For j = 2 To 10
   If crit(j, 1) = alldata(i, 12) And crit(j, 2) = alldata(i, 13) Then
     Select Case j
      Case 2, 9
       'O/s Balance and Bal as per SAP should be zero
       updateRR = alldata(i, 2) = 0 And alldata(i, 3) = 0
      Case 3
      'O/s Balance and bal as per SAP as on Amount should be between + or – 250
       updateRR = alldata(i, 2) >= -250 And alldata(i, 2) <= 250 And alldata(i, 3) >= -250 And alldata(i, 3) <= 250
      Case 4
      'O/s Balance should be 0 and unallocated payment amount is greater than 0
       updateRR = alldata(i, 2) = 0 And alldata(i, 4) > 0
       Case 5, 6, 7
       'Qty Dispute is non zero, QV is greater thanPV and Unadjusted Claim
       ' I don't know what QV and PV is!! Same with case 6 and 7
       Case 8
       'O/s Balance Amount should be between + or – 250 and bal as per SAP as on amount is Zero
       updateRR = alldata(i, 2) > -250 And alldata(i, 2) < 250 And alldata(i, 3) = 0
       Case 10
       'O/s Balance and Bal as per SAP should be non zero
        updateRR = alldata(i, 2) <> 0 And alldata(i, 3) <> 0
      End Select
    If updateRR Then
     outarr(i, 1) = crit(j, 4)
     outarr(i, 2) = crit(j, 5)
     Exit For
    End If
   End If
  Next j
 Next i
Range(.Cells(1, 10), .Cells(lastrow, 11)) = outarr
End With
 
 
End Sub






 
Upvote 0
Hi Offthelp,

Thanks for your help, I will modify remaining part and test it. ?



Thanks
mg

 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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