C
Charles
Dear all
I have the following problem. I created a function in VBA which I use
as a formula in my Excel spreadsheet. The issue is that I use it in
many many cells. As a result, the spreadsheet takes something like 3 to
4 minutes to calculate. So every millisecond I save on the calculation
of this function means much more confort for the user of the
spreadsheet.
I am not an expert in VBA/Formula using VBA. Would anyone have an idea
on how to improve the following function?
Public Function CX_TO_C1(A As Range, B As Range, C As Range,
compartment As Double) As Double
Dim nbrow, i, imax As Integer
nbrow = A.Rows.Count
imax = nbrow
If nbrow > 130 Then
imax = 130
End If
Dim temptotal As Double
temptotal = 0
For i = 1 To imax
If C.Rows(i).Value = compartment Then
temptotal = temptotal + A.Rows(i).Value * B.Rows(nbrow + 1
- i).Value
End If
Next i
CX_TO_C1 = temptotal / 100
End Function
Is there a better (and faster) way to manipulate cells? Would it be
better to copy every cell in an array at the begining? Any other
suggestion?
I thank you in advance for your help
Best regards
Charles
I have the following problem. I created a function in VBA which I use
as a formula in my Excel spreadsheet. The issue is that I use it in
many many cells. As a result, the spreadsheet takes something like 3 to
4 minutes to calculate. So every millisecond I save on the calculation
of this function means much more confort for the user of the
spreadsheet.
I am not an expert in VBA/Formula using VBA. Would anyone have an idea
on how to improve the following function?
Public Function CX_TO_C1(A As Range, B As Range, C As Range,
compartment As Double) As Double
Dim nbrow, i, imax As Integer
nbrow = A.Rows.Count
imax = nbrow
If nbrow > 130 Then
imax = 130
End If
Dim temptotal As Double
temptotal = 0
For i = 1 To imax
If C.Rows(i).Value = compartment Then
temptotal = temptotal + A.Rows(i).Value * B.Rows(nbrow + 1
- i).Value
End If
Next i
CX_TO_C1 = temptotal / 100
End Function
Is there a better (and faster) way to manipulate cells? Would it be
better to copy every cell in an array at the begining? Any other
suggestion?
I thank you in advance for your help
Best regards
Charles