Thread
:
Converting Excel Formula Arrays to Dynamic VB Array Code Help
View Single Post
#
4
Posted to microsoft.public.excel.programming
Claus Busch
external usenet poster
Posts: 3,872
Converting Excel Formula Arrays to Dynamic VB Array Code Help
Hi Andrew,
Am Thu, 18 Aug 2016 06:17:15 -0700 (PDT) schrieb
:
ColA ColB ColC
Build Reading Result
VP 6.5 PASS
VP 5.8 PASS
VP 1078 FAIL
VP 260 FAIL
VP 117 FAIL
VP 115 FAIL
VP 224 FAIL
VP 15.2 PASS
now a version with a better table layout:
Sub Test()
Dim LRow As Long, i As Long, j As Long, n As Long
Dim varData As Variant, varOut() As Variant
Dim varBuild As Variant, varResult As Variant
Dim myDic1 As Object, myDic2 As Object
Dim strFrml As String
Set myDic1 = CreateObject("Scripting.Dictionary")
Set myDic2 = CreateObject("Scripting.Dictionary")
With Sheets("Sheet1")
LRow = .Cells(Rows.Count, 1).End(xlUp).Row
varData = .Range("A2:C" & LRow)
For i = LBound(varData) To UBound(varData)
myDic1(varData(i, 1)) = varData(i, 1)
myDic2(varData(i, 3)) = varData(i, 3)
Next
varBuild = myDic1.items
varResult = myDic2.items
ReDim Preserve varOut(myDic1.Count * myDic2.Count, 4)
varOut(n, 0) = "Build": varOut(n, 1) = "Result": varOut(n, 2) = "Min"
varOut(n, 3) = "Max": varOut(n, 4) = "Average"
For i = LBound(varBuild) To UBound(varBuild)
For j = LBound(varResult) To UBound(varResult)
strFrml = "(IF((A2:A" & LRow & "=""" & varBuild(i) & """)*(C2:C" _
& LRow & "=""" & varResult(j) & """),B2:B" & LRow & "))"
n = n + 1
varOut(n, 0) = varBuild(i)
varOut(n, 1) = varResult(j)
varOut(n, 2) = Evaluate("=MIN" & strFrml)
varOut(n, 3) = Evaluate("=MAX" & strFrml)
varOut(n, 4) = Evaluate("=AVERAGE" & strFrml)
Next
Next
With .Range("G1:K1")
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
.Range("G1").Resize(UBound(varOut) + 1, 5) = varOut
End With
End Sub
@ Garry:
You can't initialize a string with variables when these are not yet
initialized. You will get a runtime error.The formula string must be
placed into the loop.
Regards
Claus B.
--
Windows10
Office 2016
Reply With Quote
Claus Busch
View Public Profile
Find all posts by Claus Busch