VlookupAllSum=SUMPRODUCT

Spielmann

Board Regular
Joined
Nov 9, 2008
Messages
105
Hi Colleagues,

I behind developed to a time a function of Addition with an only conditional criterion.
I would like to extend at least for three criteria, this function I function accurately as the function SUMPRODUCT alone that done in VBA.
Somebody could help me to develop?

Debtor

Function VlookupAllSum(name As String, IntervalSearches As Range, IntervalReturn As Range) As Variant ' as integer para valores até 32.767
Dim Valor, Nome
Dim lin, col As Integer
Dim Total
Application.Volatile
lin = 1
col = lin
For Each Nome In IntervalSearches
If Nome = name Then
Valor = IntervalReturn(lin, col)
Total = Total + Valor
VlookupAllSum = Total
End If
lin = lin + 1
Next Nome
VlookupAllSum = Total
End Function

Ex:=VlookupAllSum(A1,A1:A6,C1:C6)=33
=SUMPRODUCT(--(A1:A6=A1),(--(C1:C6)))

=VlookupAllSum(A4,A1:A6,C1:C6)=54
=SUMPRODUCT(--(A1:A6=A4),(--(C1:C6)))
A----------------B-------C
<TABLE style="WIDTH: 144pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=192 border=0 x:str><COLGROUP><COL style="WIDTH: 48pt" span=3 width=64><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 48pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" width=64 height=17>A</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 48pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right width=64 x:num>1</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 48pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right width=64 x:num>10</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>A</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>2</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>11</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>A</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>3</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>12</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>B</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>1</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>15</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>B</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>2</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>19</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; BACKGROUND-COLOR: transparent" height=17>B</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>3</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>20</TD></TR></TBODY></TABLE>


Spielmann .^.
 
Gettingbetter,
It was accurately this that I needed, but the function locks when trying to rewrite.
It would be to ask for very, to correct this imperfection.
It was very better of what it imagined, therefore still appears transcribed with the SUMPRODUCT
Thanks a lot….:pray:(y)
Spielmann:LOL:
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I obtained to develop following the line of reasoning in VBA and disponibilizo the function of Addition with multiple criteria, that is with three criteria and the interval of addition.
Debtor to all.

Function VlookupAllSum(IntervalReturn As Range, name As Variant, IntervalSearches As Range, Optional name2 As Variant, Optional IntervalSearches2 As Range, Optional name3 As Variant, Optional IntervalSearches3 As Range) As Double
Dim rngSearch As Range, dblSoma As Double, strFirstAddress As String, blCálculo As Boolean, blAutorização As Boolean
If Not IntervalSearches2 Is Nothing Then
If Not IntervalSearches3 Is Nothing Then
If IntervalReturn.Columns.Count = 1 Or IntervalSearches.Columns.Count = 1 Or IntervalSearches2.Columns.Count = 1 Or IntervalSearches3.Columns.Count = 1 Then
If IntervalReturn.Cells.Count = IntervalSearches.Cells.Count And IntervalReturn.Cells.Count = IntervalSearches2.Cells.Count And IntervalReturn.Cells.Count = IntervalSearches3.Cells.Count Then
blAutorização = True
End If
End If
Else
If IntervalReturn.Columns.Count = 1 Or IntervalSearches.Columns.Count = 1 Or IntervalSearches2.Columns.Count = 1 Then
If IntervalReturn.Cells.Count = IntervalSearches.Cells.Count And IntervalReturn.Cells.Count = IntervalSearches2.Cells.Count Then
blAutorização = True
End If
End If
End If
Else
If IntervalReturn.Columns.Count = 1 Then
If IntervalReturn.Cells.Count = IntervalSearches.Cells.Count Then
blAutorização = True
End If
End If
End If

If blAutorização Then

Set rngSearch = IntervalSearches.Find(name, , , xlWhole)

If Not rngSearch Is Nothing Then
strFirstAddress = rngSearch.Address
Do
If Not IntervalSearches2 Is Nothing Then
If name2 = IntervalSearches2(rngSearch.Row - IntervalSearches.Row + 1) Then
blCálculo = True
If Not IntervalSearches3 Is Nothing Then
If name3 = IntervalSearches3(rngSearch.Row - IntervalSearches.Row + 1) Then
blCálculo = True
Else
blCálculo = False
End If
End If
End If
Else
blCálculo = True
End If
If blCálculo Then
dblSoma = dblSoma + IntervalReturn(rngSearch.Row - IntervalReturn.Row + 1)
blCálculo = False
End If
Set rngSearch = IntervalSearches.Find(name, rngSearch, , xlWhole)
Loop While Not rngSearch Is Nothing And rngSearch.Address <> strFirstAddress
End If
VlookupAllSum = dblSoma
Set rngSearch = Nothing
Else
Error 11
End If
End Function

(y)
Debtor to all.
 
Upvote 0
I need to make a adjustment in the function increasing for plus a name and an interval of search

Somebody can help me, please?

add: Optional nome4 As Variant, Optional IntervaloProcura4 As Range

Function ProcvMultiSoma(IntervaloSoma As Range, nome As Variant, IntervaloProcura As Range, Optional nome2 As Variant, Optional IntervaloProcura2 As Range, Optional nome3 As Variant, Optional IntervaloProcura3 As Range) As Double<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Dim rngSearch As Range, dblSoma As Double, strFirstAddress As String, blCálculo As Boolean, blAutorização As Boolean<o:p></o:p>
<o:p> </o:p>
If Not IntervaloProcura2 Is Nothing Then<o:p></o:p>
If Not IntervaloProcura3 Is Nothing Then<o:p></o:p>
If IntervaloSoma.Columns.Count = 1 Or IntervaloProcura.Columns.Count = 1 Or IntervaloProcura2.Columns.Count = 1 Or IntervaloProcura3.Columns.Count = 1 Then<o:p></o:p>
If IntervaloSoma.Cells.Count = IntervaloProcura.Cells.Count And IntervaloSoma.Cells.Count = IntervaloProcura2.Cells.Count And IntervaloSoma.Cells.Count = IntervaloProcura3.Cells.Count Then<o:p></o:p>
blAutorização = True<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
Else<o:p></o:p>
If IntervaloSoma.Columns.Count = 1 Or IntervaloProcura.Columns.Count = 1 Or IntervaloProcura2.Columns.Count = 1 Then<o:p></o:p>
If IntervaloSoma.Cells.Count = IntervaloProcura.Cells.Count And IntervaloSoma.Cells.Count = IntervaloProcura2.Cells.Count Then<o:p></o:p>
blAutorização = True<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
Else<o:p></o:p>
If IntervaloSoma.Columns.Count = 1 Then<o:p></o:p>
If IntervaloSoma.Cells.Count = IntervaloProcura.Cells.Count Then<o:p></o:p>
blAutorização = True<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
<o:p></o:p>
If blAutorização Then<o:p></o:p>
<o:p></o:p>
Set rngSearch = IntervaloProcura.Find(nome, , , xlWhole)<o:p></o:p>
<o:p></o:p>
If Not rngSearch Is Nothing Then<o:p></o:p>
strFirstAddress = rngSearch.Address<o:p></o:p>
Do<o:p></o:p>
If Not IntervaloProcura2 Is Nothing Then<o:p></o:p>
If nome2 = IntervaloProcura2(rngSearch.Row - IntervaloProcura.Row + 1) Then<o:p></o:p>
blCálculo = True<o:p></o:p>
If Not IntervaloProcura3 Is Nothing Then<o:p></o:p>
If nome3 = IntervaloProcura3(rngSearch.Row - IntervaloProcura.Row + 1) Then<o:p></o:p>
blCálculo = True<o:p></o:p>
Else<o:p></o:p>
blCálculo = False<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
End If<o:p></o:p>
Else<o:p></o:p>
blCálculo = True<o:p></o:p>
End If<o:p></o:p>
If blCálculo Then<o:p></o:p>
dblSoma = dblSoma + IntervaloSoma(rngSearch.Row - IntervaloSoma.Row + 1)<o:p></o:p>
blCálculo = False<o:p></o:p>
End If<o:p></o:p>
Set rngSearch = IntervaloProcura.Find(nome, rngSearch, , xlWhole)<o:p></o:p>
Loop While Not rngSearch Is Nothing And rngSearch.Address <> strFirstAddress<o:p></o:p>
End If<o:p></o:p>
ProcvMultiSoma = dblSoma<o:p></o:p>
Set rngSearch = Nothing<o:p></o:p>
Else<o:p></o:p>
Error 11<o:p></o:p>
End If<o:p></o:p>
End Function<o:p></o:p>
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,581
Members
449,089
Latest member
Motoracer88

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