+ Reply to Thread
Results 1 to 3 of 3

vba SumProduct Multiple Condition

Hybrid View

gingank vba SumProduct Multiple... 07-21-2012, 01:16 AM
StevenM Re: vba SumProduct Multiple... 07-21-2012, 10:52 AM
oeldere Re: vba SumProduct Multiple... 07-21-2012, 11:16 AM
  1. #1
    Registered User
    Join Date
    07-17-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    48

    Lightbulb vba SumProduct Multiple Condition

    I have an error on doing the sumproduct function on the vba.
    It should be sheet1(cont no) = sheet2(cont no) & sheet1(amount) = sheet2(amount)
    then copy the sheet2 info into sheet3.
    But why it will copy all info into sheet3 below is my coding.


    Sheet 1
    no Cont no amount
    a 111 10
    b 333 10
    c 222 20
    d 444 20
    e 555 20
    f 222 10

    Sheet 2

    no Cont no amount
    a 111 20
    b 333 20
    c 333 10
    d 444 20
    e 555 20
    f 222 10

    sheet 3
    no Cont no amount
    a 111 20
    b 333 20


          With worksheets("sheet3")
      lastrow = Worksheets("CMPK").Cells(Rows.Count, 1).End(xlUp).Row
                Set R1 = Worksheets("CMPK").Range("A1:A" & lastrow)
                Set R2 = Worksheets("CMPK").Range("C1:C" & lastrow)
            For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
                .Range("Q11") = ""
                Application.StatusBar = "Actioning 1 of 3 Row: " & i
                cont_no = Cells(i, 2)
                amount = Cells(i, 9)
               myval = Evaluate("SumProduct(((" & R1.Address & ")= """ & cont_no & """) * ((" & R2.Address & ")<> """ & amount & """))")
                If myval = 0 Then
                   Cells(i, 1).Resize(1, 12).Copy Destination:=.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
                End If
    End With
            Next i

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: vba SumProduct Multiple Condition

    I would be better if you uploaded a workbook.

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: vba SumProduct Multiple Condition

    Maybe you can better first answer the questions in the other started threats.

    See:

    http://www.excelforum.com/excel-prog...html?p=2866355

    http://www.excelforum.com/excel-gene...e-cateria.html

    And a found another simular item.

    http://www.excelforum.com/excel-prog...f-problem.html
    Last edited by oeldere; 07-21-2012 at 11:20 AM.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

+ 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