+ Reply to Thread
Results 1 to 3 of 3

Conditional product

Hybrid View

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    Berkeley, CA
    MS-Off Ver
    Excel 2008 for Mac
    Posts
    1

    Conditional product

    Hi Excel forum,

    I'm a relatively newbie user trying to do the following:

    Multiply each value in A1:20 by each value in B1:20 and sum them all, EXCEPT for A1*B1, A2*B2, etc. Such that we have A1*B2 + A1*B3 +...+ A2*B1 + A2*B3 +...

    I imagine it's a simple fix I can't figure out how to do it for the life of me using array functions >_< Will I have to get into the VBA code? I have yet to explore that realm..

    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Conditional product

    will this macro help you

    Sub test()
    Dim j As Long, k As Long, ssum As Double
    k = 1
    ssum = 0
    Do
    For j = 1 To Range("A1").End(xlDown).Row
    ssum = ssum + Cells(j, 1) * Cells(j, 1).Offset(k, 1)
    Next j
    k = k + 1
    If k > Range("B1").End(xlDown).Row Then Exit Do
    Loop
    MsgBox ssum
    End Sub

  3. #3
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Conditional product

    This maby?

    Sub steffen()
    
    For Each xCell In Range("A1:A20")
        cRow = xCell.Row
        For i = 1 To 20
            If i = cRow Then
                ' Do nothing
            Else
                Total = Total + (xCell * Cells(cRow, 2))
            End If
        Next i
    Next xCell
    
    MsgBox (Total)
    
    End Sub

+ 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