Excel - rekursives VLOOKUP
-
14-11-2019 - |
Frage
Ich kam kürzlich über Strg + Shift + ein, um Array-Formeln von Excel einzugeben, und lernten sie derzeit noch.Zu meinem Problem kommen, generasacodicetagpre.
Ich muss die Summe aller Einrückungen eines bestimmten Produktnamens ausführen.
zB: Ich brauche den totalen Gedankenstrich von S1,
- vlookup auf dem blatt, erhalten Sie den Code 19875
- Führen Sie einen VLOOKUP auf Sheeth aus, holen Sie den Inzug von 40
- Nächstes VLOOKUP auf BLATT A, erhalten Sie den Code 13575
- Verwenden Sie 13575 mit dem VLOOKUP auf Sheeth, erhalten Sie einen Inzug von 22
- Nächster VLOOKUP auf BLATT A, erhalten Sie den Code 35675
- Verwenden Sie 35675 zum VLOOKUP auf Sheeth, erhalten Sie einen Inzug von 25
- Summe von 40 + 22 + 25, Rückgabe 87
Ich kann das durch VBA erreichen, aber ich frage mich, ob dies in Excel-Funktionen mit CSE / ARRAY-Formeln möglich ist.
edit:
Ich habe keine Werte in Sheet2 in derselben Reihenfolge von Sheet1 .. Sie sind vollständig zufällig.Mein Sheeth ist etwas zufällig wie folgt: generasacodicetagpre.
Lösung
{=SUM(NOT(ISNA(MATCH((($A$2:$A$6="S1")*(B2:B6)),Sheet2!$A$2:$A$6,FALSE)))*(Sheet2!$B$2:$B$6))}
The first argument of the MATCH resolves to
{19875;0;13575;35675;0}
The MATCH resolves to
{1;#N/A;3;4;#N/A}
You'll have to make sure you don't have zeros in SheetB. The NOT ISNA turns those into TRUEs and FALSEs and resolves to
{TRUE;FALSE;TRUE;TRUE;FALSE}
And the final SUM looks like this
=SUM({TRUE;FALSE;TRUE;TRUE;FALSE}*{40;15;22;25;20})
Update
I can't figure out a single-array solution when the lists are in a different order. My attempts with OFFSET and TRANSPOSE either gave the wrong answer or crashed Excel. If you can stand using a helper column, you could put this formula in third column of your first sheet
=VLOOKUP(B2,Sheet2!$A$2:$B$6,2,FALSE)
and then use this array formula to sum them up
{=SUM(($A$2:$A$6=A2)*($C$2:$C$6))}
Andere Tipps
If the Code column were identical (same order) on both SheetA and SheetB, a simple SUMIF function would do. Similarly, if the INDENT data were on SheetA, you could also use a pivot table to calculate the sums quickly.
I'm guessing the design of your workbook won't allow this though. In which case, I don't have any easy solutions, but I'll give it another look.
You could use the below: //Ola.S
Table 1 Col:A B C Product Code Intendent
Col C: =SUMIF($E$4:$E$8;B4;$F$4:$F$8)
Table 2 Col:E F Code Intendent
Table 3 Pivottable (Col:A and C)
On sheetC If A1 has S1 then in Cell B1 type
=SUM((IF((Product=A1),Code1)=TRANSPOSE(Code2))*TRANSPOSE(Amt))
Array entered Where Code1 = Dynamic Range for Codes on SheetA starting from Row2 Code2 = Dynamic Range for Codes on SheetB starting from Row2
No TRANSPOSE
calls needed.
Try the array formula
=SUM(SUMIF(SheetB!A2:A6,IF(SheetA!A2:A6="S1",SheetA!B2:B6),SheetB!B2:B6))
Assuming no cell in SheetB!A2:A6
it evaluates to FALSE. If the Code columns were all numeric (probably a questionable assumption), this could be done without an array entry using:
=SUMPRODUCT(SUMIF(SheetB!A2:A6,SheetA!B2:B6/(SheetA!A2:A6="S1"),SheetB!B2:B6))
Assuming no cell in SheetB!A2:A6
evaluates to #DIV/0!
.