Thanks Peter for your time,
Mine is somehow similar to the code you wrote. I have found out that the
problem is where the arrow is as below:
//////////////////////////////////////////////////
''Array method
t = GetTickCount
Set rng = [b1:f10000]
vArr = rng
ReDim nArr(1 To rng.Rows.Count, 1 To 1) As Long
rw = rng.Rows.Count
cl = rng.Columns.Count
For i = 1 To rw
x = 0
For j = 1 To cl
==========> x = x + vArr(i, j)
Next
nArr(i, 1) = x
Next
[j1:j10000].Value = nArr
Debug.Print "Array calc " & GetTickCount - t
//////////////////////////////////////////////////
Following is my sub:
//////////////////////////////////////////////////
Public Sub printFormulaTable(Optional ByVal formulaColumns As String =
"#control#")
On Error GoTo errHandle
Dim i As Integer, j As Integer
Dim Temp As Variant
Dim count1 As Integer, count2 As Integer
If IsEmpty(rawData) Then setupArrays
Dim n As Date
n = Time()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If formulaColumns = "#control#" Then
formulaColumns = ""
For i = 1 To UBound(fList, 1)
If fList(i, 3) = True Then
formulaColumns = formulaColumns & "," & fList(i, 1)
End If
Next i
formulaColumns = Mid(formulaColumns, 2)
End If
If Len(formulaColumns) > 0 Then
Temp = Split(formulaColumns, ",")
count1 = UBound(Temp) + 1 ' number of formula columns from 0 ->
count1
count2 = UBound(rawData, 1) ' number of rows except header row
in rawData
ReDim mainData(count2, count1) As Variant
For j = 0 To count1 - 1
mainData(1, j + 1) = Temp(j)
For i = 2 To count2
=== PROBLEM ===> mainData(i, j + 1) = fEvaluate(Temp(j), i)
Next i
Next j
With wsMainData
.Range(.Cells(1, 1), .Cells(count2, count1)).Delete
.Range(.Cells(1, 1), .Cells(count2, count1)).FormulaArray =
mainData
.Range(.Cells(1, 1), .Cells(count2, count1)).name =
"Database2"
End With
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox n & vbCrLf & Time
Exit Sub
errHandle:
writeLog "printFormulaTable", " error " & Err & ": " & Error(Err) &
" i=" & i & " j=" & j
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub 'printFormulaTable
//////////////////////////////////////////////////
User-defined fEvaluate() function takes a formula as parameter than it
will substitute relevant values for each variable in the formula and
finally return calculated result.
It is ok if the array has less than about 300 rows and 150 columns.
I know it is better to let Excel does this job. But my task is that I
have to produced complicated reports that based on violated calculated
values (not the original).
I also know that it is faster and easier to do it in MS Access 'cause I
have done this before. But I am required to do this in Excel.
I have been trying many methods to reach as close as I can. I am really
appreciate any idea or suggestion from you.
Best regards,