Consulting

Results 1 to 8 of 8

Thread: Error with sumproduct

  1. #1

    Error with sumproduct

    Hi everybody
    I wrote the following code but I encountered an error at the line of sumproduct

    Here's the code
    [VBA]Dim LastRow As Integer: Dim cel, rng, rngkind, rngsales As Range
    LastRow = Cells(Rows.Count, "D").End(xlUp).Row
    Set rng = Range("D2" & LastRow)
    Set rngkind = Range("Kind")
    Set rngsales = Range("Sales")
    Application.ScreenUpdating = False
    For Each cel In rng
    cel.Offset(0, 2) = Application.WorksheetFunction.SumProduct((rngkind = cel.Value) * (rngsales))
    Next cel
    Application.ScreenUpdating = True
    [/VBA]

  2. #2

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    From memory, SumProduct is not available as a WorksheetFunction within vba. You can use Evaluate though.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    cel.Offset(0, 2) = Application.Sumif(rngkind, cel.Value, rngsales)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Thank you very much
    It's nice to have different solutions
    Here's another link to the same problem
    http://www.mrexcel.com/forum/showthread.php?t=505572

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Oh, so you are a cross-poster. Thanks for the info, I know to ignore your posts now.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Oh, so you are a cross-poster. Thanks for the info, I know to ignore your posts now.
    Sorry Mr. xld but I was in a bad need to correct the code
    And when I can't get a quick solution, I tried MrExcel to have a quick one
    My apology for you...!!

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You don't have to apologise to me, I am a free person and I make my own choices just as you do.

    I don't like cross-posting as I feel it shows a total disregard for the people who try and help provide solutions, and as I such as soon as I know about cross-posting I will not get involved in trying to help provide that person a solution, even if it is clear that they still require one.

    And, I take that approach forward into future posts.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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