none
How to iterate over m rows in Excel spreadsheet and select several cells(m, n) to sum and multiple them up in VBA? RRS feed

  • Question

  • Hello all,

    how would one iterate over m rows (with n columns, but n = m) in a spreadsheet and select several entries, call them cell(m, n) with fixed m for each step, such that they can multiply cell(m, arg1) * . . . * cell(m, argN) with given parameters arg1, . . ., argN that were passed to this defined function.  How would I do this in VBA?

    For example, 

    double wholeLife(a, b, c){

    double benefit = 0;

    for(m = 1; m <=dim(matrix(m, n)); m++){

    benefit = benefit + cell(m, a) * cell(m, b) * cell(m, c); 

    }

    return benefit; 

    }//How would I do this in VBA?






    • Edited by Jack101101 Wednesday, November 1, 2017 1:59 AM
    Tuesday, October 31, 2017 10:52 PM

Answers


  • Function wholeLife(benefit ,m , sup, a, b, c)
    Dim Ax As Double
    Ax = 0
    For m To sup
    Ax = Ax + Cells(m, a) * Cells(m, b) * Cells(m, c)
    Next
    wholeLife = benefit * Ax
    End Function
    • Marked as answer by Jack101101 Wednesday, November 1, 2017 12:50 AM
    Wednesday, November 1, 2017 12:48 AM