Excel - Calculating formula taking too long. Is there an alternative to the below formula.

mrsushi

Board Regular
Joined
Nov 18, 2006
Messages
180
Office Version
  1. 2010
I have the below formula which references another sheet and returns the total summary value on sheet lp99. However, the sheet(Paste LP99) has over 200,000 lines of data and the calculation takes near enough 45min - 1 hour to calculate. Is there a alternative which can be used in order to speed up the calculation? Ive heard arrays could work but not used these before?


SUMIF('PASTE LP99'!A:A, A43, 'PASTE LP99'!L:L)
SUMIF('PASTE LP99'!A:A, A43, 'PASTE LP99'!V:V)


Any help would be much appreciated

Many thanks
M
 
Did you change both instances of Sheets("Sheet1") to Sheets("Available Prices")
I've rerun the macro and just uncovered that the macro did populate results. However, a number of cells havent pulled any figures in. The below is the macro used


VBA Code:
Sub mrsushi1()

   Dim Ary As Variant, Oary As Variant

   Dim Dic As Object

   Dim r As Long

 

   Set Dic = CreateObject("Scripting.dictionary")

   With Sheets("PASTE LP99")

      Ary = .Range("A2:L" & .Range("A" & Rows.Count).End(xlUp).Row).Value2

   End With

   For r = 1 To UBound(Ary)

      Dic(Ary(r, 1)) = Dic(Ary(r, 1)) + Ary(r, 12)

   Next r

   With Sheets("Available Prices")

      Ary = .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Value2

      Oary = .Range("AA2:AA" & .Range("A" & Rows.Count).End(xlUp).Row).Value2

   End With

   For r = 1 To UBound(Ary)

      Oary(r, 1) = Dic(Ary(r, 1))

   Next r

   Sheets("Available Prices").Range("AA2").Resize(UBound(Oary)).Value = Oary

End Sub
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Ok, are those Serdols without values definately in the other sheet?
Also with values like B1G2932 could they also be like b1g2932 or will they always be upper case letters only?
 
Upvote 0
Ok, are those Serdols without values definately in the other sheet?
Also with values like B1G2932 could they also be like b1g2932 or will they always be upper case letters only?
Hi. Sorry to keep you waiting. I've doubled checked the data on the LP99 Report. Its appears that its missing that data which is therefore returning nil. The formula appears to work fine but will need to do some more spot checks.

Thank you very much for your help in resolving this issue. Its cut down the processing time almost from 2 hours to 5 seconds. This will definitely stop my boss from roasting my backside and enable me to collate the data successfully.

Much appreciated and many thanks for your time this evening.

If there is an issue down the line, would this email thread still be around?

Regards
Martin
 
Upvote 0
Glad to help & thanks for the feedback.
Should you have a problem in the near future post back here, otherwise it would be better to start a new thread.
 
Upvote 0
Glad to help & thanks for the feedback.
Should you have a problem in the near future post back here, otherwise it would be better to start a new thread.
Thanks Fluff.

One question i forgot to ask is which line of the code does the SUMIF part? Havent looked closely at Arrays before so trying to figure this out.

Many thanks
M
 
Upvote 0
This line is adding the values depending on the key in the dictionary (the value in col A)
VBA Code:
Dic(Ary(r, 1)) = Dic(Ary(r, 1)) + Ary(r, 12)
 
Upvote 0
Good afternoon,

Hope you are well.

Thankyou again for the the array formula above. I have another issue where some of the columns have returned a zero/blank value. Without making this too complicated, would you be able to provide an additional formula to look through the Column AA and look for blanks, then apply a SUMIF formula again but referencing ("Paste 99" sheet) Column B2:L column?

Macro at the moment is
1st Macro = Based on Column A(Available Prices) Sumifs A2: L (Sheet - Paste 99)

Additional Macro
2nd Macro = Look for any blanks in Cell AA and then base on Column B (Available prices - secondary ID), SumIF B2:L (Sheet - Paste99)

Many thanks
M
 
Upvote 0
Try
VBA Code:
Sub mrsushi()
   Dim Ary As Variant, Oary As Variant
   Dim Dic As Object, Dic2 As Object
   Dim r As Long
   
   Set Dic = CreateObject("Scripting.dictionary")
   Set Dic2 = CreateObject("Scripting.dictionary")
   With Sheets("Paste 99")
      Ary = .Range("A2:L" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   For r = 1 To UBound(Ary)
      Dic(Ary(r, 1)) = Dic(Ary(r, 1)) + Ary(r, 12)
      Dic2(Ary(r, 2)) = Dic2(Ary(r, 2)) + Ary(r, 12)
   Next r
   With Sheets("Available Prices")
      Ary = .Range("A2:B" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
      Oary = .Range("AA2:AA" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   For r = 1 To UBound(Ary)
      If Dic.Exists(Ary(r, 1)) Then
         Oary(r, 1) = Dic(Ary(r, 1))
      Else
         Oary(r, 1) = Dic2(Ary(r, 2))
      End If
   Next r
   Sheets("Available Prices").Range("AA2").Resize(UBound(Oary)).Value = Oary
End Sub
 
Upvote 0
Try
VBA Code:
Sub mrsushi()
   Dim Ary As Variant, Oary As Variant
   Dim Dic As Object, Dic2 As Object
   Dim r As Long
  
   Set Dic = CreateObject("Scripting.dictionary")
   Set Dic2 = CreateObject("Scripting.dictionary")
   With Sheets("Paste 99")
      Ary = .Range("A2:L" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   For r = 1 To UBound(Ary)
      Dic(Ary(r, 1)) = Dic(Ary(r, 1)) + Ary(r, 12)
      Dic2(Ary(r, 2)) = Dic2(Ary(r, 2)) + Ary(r, 12)
   Next r
   With Sheets("Available Prices")
      Ary = .Range("A2:B" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
      Oary = .Range("AA2:AA" & .Range("A" & Rows.Count).End(xlUp).Row).Value2
   End With
   For r = 1 To UBound(Ary)
      If Dic.Exists(Ary(r, 1)) Then
         Oary(r, 1) = Dic(Ary(r, 1))
      Else
         Oary(r, 1) = Dic2(Ary(r, 2))
      End If
   Next r
   Sheets("Available Prices").Range("AA2").Resize(UBound(Oary)).Value = Oary
End Sub

Thank you very much. Initial calculation looks good .
Once again much appreciated. :) (y)

Regards
M
 
Upvote 0

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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