transforming Excel array formulas to vba
Hi
I have a huge file with very sophisticated array formulas. My problem is that due to the over 10.000 formulas everything takes forever. Each new cell value or even applying a filter results in 'calculating...'
I wonder if and how I'd be able replace the array formulas with vba.
this is the preparation of the arrays in vba:
Dim rnge As Range
Dim siteArr, hopArr, ICMSArr, ISSArr, PVvalArr, POArr, POValArr, ProjArr As Variant
Set rnge = wsPV.Range(Cells(pvRw1, hopPVc), Cells(pvRwN, hopPVc))
hopArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, ICMSPVc), Cells(pvRwN, ICMSPVc))
ICMSArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, ISSPVc), Cells(pvRwN, ISSPVc))
ISSArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, POPVc), Cells(pvRwN, POPVc))
POArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, POvalPVc), Cells(pvRwN, POvalPVc))
POValArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, PVvalPVc), Cells(pvRwN, PVvalPVc))
PVvalArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, sitePVc), Cells(pvRwN, sitePVc))
siteArr = rnge.Value
Set rnge = wsPV.Range(Cells(pvRw1, ProPVc), Cells(pvRwN, ProPVc))
ProjArr = rnge.Value
Bfter this everything is in nice one dimensional arrays
But now I'd like to find a special condition in various arrays and retrieve a value of a result array.
My worksheet formula was this
{=SUMPRODUCT((project=H6)*(hop=I6)*(site=J6)*(ICMS>0)*(PVval))}
and I'd like it to be done by vba, so I programmed this:
siteAvalPVmM = Application.WorksheetFunction.SumProduct((ProjArr = projct) * (hopArr = hop) * _
(siteArr = siteA) * (ICMSArr > 0) * (PVvalArr))
the second part is even more complex.
Worksheet formula:
{=INDEX(POnb;MATCH(1;(hop=I6)*(site=J6)*(ICMS>0);0))}
and the vba attempt:
POnbA = Application.WorksheetFunction.Index(POArr, Application.WorksheetFunction.Match(1, _
(hopArr = hop) * (siteArr = siteA) * (ICMSArr > 0), 0))
Essentially I'm looking for a unique combination in the named areas (arrays). In the latter example I want to extract the PO number for the match hop-range = hop in I6, site-range = site A and ICMS-range >0
Is there a way to do this in vba? If so could anyone give me a clue?
thanks
FBr