+ Reply to Thread
Results 1 to 4 of 4

VBA sumproduct array

Hybrid View

ludo@excelforum VBA sumproduct array 06-01-2013, 07:38 AM
:) Sixthsense :) Re: VBA sumproduct array 06-03-2013, 05:12 AM
ludo@excelforum Re: VBA sumproduct array 06-06-2013, 05:45 AM
:) Sixthsense :) Re: VBA sumproduct array 06-06-2013, 05:59 AM
  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    2

    VBA sumproduct array

    hello,

    I tried the following but it is not working ; I tried many syntaxes without any succes... can anyone helps me ? thx !!!

    Sub sumprodludo()
    
    Dim a() As Variant
    
    Sheets("trades").Range("F7471:G7487").Select
    a = Selection
    
    ff = Application.WorksheetFunction.SumProduct(((application.Index(a, 0, 1)) > 100) * (Application.Index(a, 0, 2)))
    
    End Sub
    Last edited by arlu1201; 06-01-2013 at 10:51 AM. Reason: Use code tags in future.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,789

    Re: VBA sumproduct array

    Try like this...

    Sub UsingSumproductInVBA()
    Dim rMyRng As Range, rRng1 As Range, rRng2 As Range
    Dim sFormula As String, vResult As Variant
    
    Set rMyRng = Sheets("trades").Range("F7471:G7487")
    
    With Application
        Set rRng1 = .Index(rMyRng, , 1)
        Set rRng2 = .Index(rMyRng, , 2)
    End With
    
    sFormula = "=SumProduct((" & rRng1.Address(, , , True) & "> 100) *" & rRng2.Address(, , , True) & ")"
    
    vResult = Evaluate(sFormula)
    
    MsgBox vResult
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    05-26-2013
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VBA sumproduct array

    Hello,

    thank sixthsense !!!
    all works perfectly... it makes crazy long formulas but works... that's I hope I could use arrays and make logical filters on my array A...

    another question : is it possible to make sub selections in a range or an array like other languages or like a sql/access request from excel ?
    I mean is it possible to select only rows where cells(i,2)>0 and cells(i,3)="earth" (or A(i,2)>0 and Ai,3)="earth" with A an array) and to make calculation with the sub selected rows or the sumproduct is the only way ?

    thx

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,789

    Re: VBA sumproduct array

    Some suggestions:-
    • Using Looping system
    • Using Countif in VBA
    • Using Filter

    Some more other methods may be available.....

+ 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