Assign toatal based on two criteria to variables

Snailspace

Board Regular
Joined
Jan 28, 2009
Messages
56
I’m trying to calculate the totals based on the Account number (Col E) and the aging criteria (Col J), to come up with the total for the account, and a total per account based on the aging. The idea being I can store these in variables to perform further calculations.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I tried Sumproduct, which I could only get to work if I dropped it in as a formula rather than evaluating in VBA. This seemed to be very slow. The best I’ve been able to come up with is popping it into an array and looping through. I’m sure this is not the most efficient way.
TIA
SP<o:p></o:p>
Rich (BB code):
<o:p>Dim x As Variant
Dim r As Long, c As Integer, arrRow As Long
Dim accTotal As Double
Dim d130 As Double
Dim accNo As String
x = Range("A1:M11000").Value</o:p>
<o:p>For r = 2 To UBound(x, 1)
accTotal = 0
d130 = 0
'x(r,c)
accNo = (x(r, 5))
   For arrRow = 2 To UBound(x, 1)
   'Total
      If (x(arrRow, 5)) = accNo Then
          accTotal = accTotal + (x(arrRow, 11))
      End If
  '1-30 days
      If (x(arrRow, 5)) = accNo And (x(arrRow, 10)) = "1-30 Days" Then
          d130 = d130 + (x(arrRow, 11))
      End If
Next arrRow
x(r, 12) = accTotal
x(r, 13) = d130
Next r</o:p>
<o:p>Range("A1:M11000") = x</o:p>
<o:p></o:p>
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

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