2

次のような巨大なExcelシートがあります。

╔══════╦══════╦═════╗
║  A   ║  B   ║  C  ║
╠══════╬══════╬═════╣
║ Jack ║ 2001 ║ 1,5 ║
║ Jack ║ 2002 ║ 2,0 ║
║ Jack ║ 2003 ║ 1,0 ║
║ Jack ║ 3001 ║ 3,5 ║
║ Jack ║ 3002 ║ 4,0 ║
║ Jack ║ 3003 ║ 1,0 ║
║ Jill ║ 2001 ║ 3,0 ║
║ Jill ║ 2002 ║ 5,0 ║
║ Jill ║ 2003 ║ 2,0 ║
║ Jill ║ 3001 ║ 0,5 ║
║ Jill ║ 3002 ║ 6,0 ║
║ Jill ║ 3003 ║ 2,5 ║
╚══════╩══════╩═════╝

列 B にはさまざまな数字が含まれていますが、それらはすべて 2、3、または 8 の数字で始まります。列 B の数字は常に 4 桁の長さです。私は最初の桁をチェックすることにのみ興味があります。

列 C の値を合計する必要があります。列 B の対応するセルの最初の桁は2*3*または8*です。必要なのは、これを行う数式を作成することです (Ruby 風の擬似コード)。

sum = 0
spreadsheet_rows.each do |row|
  if row.a == "Jack" and row.b == "2*" # Note the second wildcard condition.
    sum += row.c
  end
end

puts sum # Should print 4,5 in this example.

これを達成するために、Excelで次の式を使用しようとしています。

=SUMIFS($C:$C; $A:$A; "Jack"; $B:$B; "=2*")

エクセルでは数値のワイルドカード条件がサポートされていないことはわかっていますが、エクセルで列Bを「テキスト」型にフォーマットしたので、そのまま扱われると思っていたのですが、やはりintとして扱われているようです。

=SUMIFSExcel で数値にワイルドカード条件を適用する別の方法はありますか? おそらく、数式で整数を文字列に「キャスト」する方法はありますか? 私はそれを行う方法を見つけていません(まだ)。

Excel for Mac 2011 を使用しています。

4

3 に答える 3

3

I'd go for the less readable, but more powerful SUMPRODUCT:

=SUMPRODUCT(($A:$A="Jack") * (LEFT($B:$B;1)="2") * ($C:$C))

which will generate boolean arrays for each of the conditions (first and second brace part) which it will multiply with the third one (your numbers).

EDIT: As noted in comments, #VALUE errors can appear if any value in column C cannot be converted to a number. To avoid that, you could use the syntax suggested by barry houdini

=SUMPRODUCT(($A:$A="Jack") * (LEFT($B:$B;1)="2"); $C:$C)

and let SUMPRODUCT skip over non-numbers.

于 2014-09-01T09:13:08.060 に答える
1

This works for me:

=SUM((A1:A12=F2)*(LEFT(B1:B12)=""&F3)*C1:C12)

entered as an array formula with CtrlShiftEnter

You ask how to cast numbers to strings; concatenating an empty string and a number ""&F3 is one way to do that.

enter image description here

于 2014-09-01T09:13:17.663 に答える