+ Reply to Thread
Results 1 to 3 of 3

More efficient way to calculate values

  1. #1
    Registered User
    Join Date
    12-28-2005
    Posts
    2

    More efficient way to calculate values

    Hi,
    I'm trying to make a function that sums values from calls that have the same outline level. Idea is to calculate only cells until the next upper level cell.

    Here is what I have done, but this function seems to be very unefficient when I'm using that in many cells to calculate quite large amount of data.

    Do you have any ideas how to make the same more efficient way?


    Function OutlineLevelSum(iLevel As Integer, rSumRange As Range)
    Dim rCell As Range
    Dim vResult

    For Each rCell In rSumRange
    If Rows(rCell.Row).OutlineLevel = iLevel Then
    vResult = vResult + rCell.Value
    ElseIf Rows(rCell.Row).OutlineLevel < iLevel Then
    Exit For
    End If
    Next rCell

    OutlineLevelSum = vResult
    End Function

  2. #2
    Niek Otten
    Guest

    Re: More efficient way to calculate values

    Maybe declaring the function itself as Double helps a bit (Function
    OLS(....) as Double)
    It avoids one Variant addition per cycle.
    I always use Long instead of Integer because that is the basic unit in
    32-bit systems. But there may be leftover instructions for Integers, I don't
    know. Just try.

    --
    Kind regards,

    Niek Otten

    "Marw" <Marw.20qvhy_1135764001.5149@excelforum-nospam.com> wrote in message
    news:Marw.20qvhy_1135764001.5149@excelforum-nospam.com...
    >
    > Hi,
    > I'm trying to make a function that sums values from calls that have the
    > same outline level. Idea is to calculate only cells until the next upper
    > level cell.
    >
    > Here is what I have done, but this function seems to be very
    > unefficient when I'm using that in many cells to calculate quite large
    > amount of data.
    >
    > Do you have any ideas how to make the same more efficient way?
    >
    >
    > Function OutlineLevelSum(iLevel As Integer, rSumRange As Range)
    > Dim rCell As Range
    > Dim vResult
    >
    > For Each rCell In rSumRange
    > If Rows(rCell.Row).OutlineLevel = iLevel Then
    > vResult = vResult + rCell.Value
    > ElseIf Rows(rCell.Row).OutlineLevel < iLevel Then
    > Exit For
    > End If
    > Next rCell
    >
    > OutlineLevelSum = vResult
    > End Function
    >
    >
    > --
    > Marw
    > ------------------------------------------------------------------------
    > Marw's Profile:
    > http://www.excelforum.com/member.php...o&userid=29934
    > View this thread: http://www.excelforum.com/showthread...hreadid=496352
    >




  3. #3
    Registered User
    Join Date
    12-28-2005
    Posts
    2
    Thanks for the idea. I did that but it doesn't seem to affect much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1