+ Reply to Thread
Results 1 to 3 of 3

Thread: VBA match 2 criteria and return a value

  1. #1
    Valued Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    446

    VBA match 2 criteria and return a value

    Hi,

    I have a feeling I need to do some sort of sumproduct, like application.sumproduct but..

    I have tried doing a simple sum product for this in excel and it isn't working.

    The reason it needs to be in VBA is because it calculates this as part of a change event and also it would be nice to learn this function within VBA.

    I need to match the value of the cell with name DTYPE to the range STYPE, I also need to match the value of cell with name DABS to the range ABSD then I need the value returning from range ABSC.

    When I tried this in excel it returned a value of 0, using this formula:

    =SUMPRODUCT((STYPE=DTYPE)*(ABSD=DABS),(ABSC))
    I have tried this function in VBA but to absolutely no result worth displaying.

    Any ideas?

    Andy
    Last edited by mcinnes01; 10-22-2010 at 06:38 AM.

  2. #2
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: VBA match 2 criteria and return a value

    In terms of conducting SUMPRODUCT in VBA

    Dim dblAns As Double
    dblAns = Evaluate("SUMPRODUCT((STYPE=DTYPE)*(ABSD=DABS),ABSC)")
    others might suggest using [ ] notation for the Evaluate
    (above assumes that code resides within the Sheet Object in VBE)

    note: the SUMPRODUCT itself assumes that ABSC has the same height and width as the result of STYPE*ABSD

  3. #3
    Valued Forum Contributor mcinnes01's Avatar
    Join Date
    05-25-2010
    Location
    Manchester
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    446

    Re: VBA match 2 criteria and return a value

    Thanks,

    Works perfectly!

    andy

+ 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.2.0