Create a sumproduct function in vba

EliSilver

New Member
Joined
Jun 19, 2019
Messages
1
Hello, I need to make a sumproduct_if function in vba, but I really don´t know how to start.

This is what I have:

Function SUMAPRODUCTO_SI(rango_1 As Range, rango_2 As Range, rango_cond As Range, condicion As String) As Double

Dim filauno As Integer, columnauno As Integer, filasuno As Integer, columnasuno As Integer
Dim filados As Integer, columnados As Integer, filasdos As Integer, columnasdos As Integer


Dim valoruno As Double
Dim valordos As Double

Dim multiplicacion As Double

Dim acumulado As Double

'Encontrar la primera celda del rango uno y del rango dos

filauno = rango_1.Row
columnauno = rango_1.Column
filasuno = rango_1.Rows.Count
columnasuno = rango_1.Columns.Count

filados = rango_2.Row
columnados = rango_2.Column
filasdos = rango_2.Rows.Count
columnasdos = rango_2.Columns.Count

For i = filauno To filauno + filasuno - 1
For j = columnauno To columnauno + columnasuno - 1
valoruno = Cells(i, j).Value
For m = filados To filados + filasdos - 1
For n = columnados To columnados + columnasdos - 1
valordos = Cells(m, n).Value
multiplicacion = (valoruno * valordos)
acumulado = acumulado + multiplicacion.Value
Next n
Next m
Next j
Next i

SUMAPRODUCTO_SI = acumulado


End Function


Please, If someone can help me...¡thank you!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top