メインコンテンツへスキップ

Excelでのみ括弧内の数値を合計するにはどうすればよいですか?

テキスト文字列のリストがあり、下のスクリーンショットに示すように括弧内のすべての数字を合計したい場合、どのようにすばやく処理できますか? この記事では、Excelでのみ括弧内の数値を合計するためのいくつかのトリックを紹介します。


数式のみを使用して括弧内の数値を合計する

角かっこ内の数値のみを合計するには、最初に角かっこ内の数値を抽出してから、それらを合計します。

1.角かっこで囲まれた数値を合計するセルの横にある空白のセルを選択します(たとえば、B2)。次の数式を入力します。
=IF(ISERROR(MID(A1,FIND("(",A1)+1,(FIND(")",A1))-(FIND("(",A1)+1))),0,(MID(A1,FIND("(",A1)+1,(FIND(")",A1))-(FIND("(",A1)+1)))+0),
次に、自動入力ハンドルを下にドラッグして、各セルから角かっこで囲まれた数値を抽出します。 スクリーンショットを参照してください:
括弧内のドキュメント合計番号2

先端:数式で、A1は、角かっこ内の数値を抽出するセルです。

2.合計結果を配置するセルを選択し、次のように入力します。 = SUM(B1:B8)、プレス 入力します キー。 スクリーンショットを参照してください:
括弧内のドキュメント合計番号3

ヒント: 式で、B1:B8は、テキスト文字列の元のリストから抽出した、合計したい数値です。


定義された関数でのみ括弧内の数値を合計する

定義済み関数を適用して、角かっこ内の数値を合計することもできます。

1。 押す Altキー+ F11 有効にするキー アプリケーション向け Microsoft Visual Basic ウィンドウ、クリック インセット > モジュール、以下のコードを空白のスクリプトに貼り付けます。

VBA:括弧内の合計数

Function SumBracket(Target As Range) As Double
'UpdatebyExtendoffice20160901
Dim xCell As Range
Dim xObjs As Object, xObj As Object
Dim xSum As Double
Set xObjs = CreateObject("VBScript.RegExp")
xSum = 0
With xObjs
    .Global = True
    .Pattern = "\((\d+(\.\d+)?)\)"

    For Each xCell In Target
      If xCell.Value <> "" Then
        For Each xObj In xObjs.Execute(xCell.Value)
            xSum = xSum + xObj.submatches(0)
        Next
      End If
    Next
End With
SumBracket = xSum
End Function

括弧内のドキュメント合計番号4

2.コードを保存し、結果を配置するセルを選択して、この数式を入力します = SumBracket(A1:A8)、 押す 入力します キー。 スクリーンショットを参照してください:
括弧内のドキュメント合計番号5


Kutools forExcelでのみ括弧内の数値を合計する

実は Kutools for Excelさん テキストを抽出 角かっこ内の数値を抽出し、を適用する関数 絶対値の合計 数値を合計する関数。

Kutools for Excel, 以上で 300 便利な機能は、あなたの仕事をより簡単にします。 

インストールした後 Kutools for Excel、以下のようにしてください:(今すぐExcel用のKutoolsを無料でダウンロードしてください!)

1.角かっこで囲んだ数字を抽出する文字列を選択し、をクリックします クツールs> テキスト > テキストを抽出。 スクリーンショットを参照してください:
括弧内のドキュメント合計番号6

2。 の中に テキストを抽出 ダイアログ、入力 (*)テキスト テキストボックスをクリックし、 Add それを リストの抽出。 次に、をクリックします Ok、セルを選択して、抽出した数値をポップダイアログに配置します(例:C1)。 スクリーンショットを参照してください:

注: に他の抽出ルールがある場合 リストの抽出 セクションでは、これらの抽出ルールのチェックを外し、新しく追加された抽出ルールのみをチェックしてください。 (*).


括弧内のドキュメント合計番号7 右矢印を撃った 括弧内のドキュメント合計番号8

3。 クリック OK、および括弧内の数字が抽出されます。 デフォルトでは、括弧内の数値は負として認識されるため、絶対値を合計する必要があります。
括弧内のドキュメント合計番号9

4.計算結果を配置するセルを選択し、をクリックします クツール > フォーミュラヘルパー > 数学と三角法 > 絶対値の合計。 スクリーンショットを参照してください:
括弧内のドキュメント合計番号10

5。 の中に フォーミュラヘルパー ダイアログで、抽出された数値を含む範囲を選択します テキストボックス、この場合はC1:C8。 クリック Ok、数値の絶対値が追加されました。 スクリーンショットを参照してください:

括弧内のドキュメント合計番号11 右矢印を撃った 括弧内のドキュメント合計番号12

ヒント。 の無料トライアルをご希望の場合 テキストを抽出 & 絶対値の合計s関数、 Excel用のKutoolsを無料でダウンロードしてください まず、上記の手順に従って操作を適用します。

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (15)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello Sunny,

I have a question as well. I have an excel sheet with numbers and some of them are in brackets. I want to add the values of the numbers in a row. Basically:
50 (50*) 100 150 = 350
How can I add (=sum) of all of them, including the one in brackets? I'ld appreciate your advise.
Best, Anna
This comment was minimized by the moderator on the site
Vielen Dank Sonnig,

jetzt ich sehe wo war das Problem. Sie schreiben im VBA und Zelle "." statt wie bei mir "," Ich habe im VBA diese Zeile:
.Pattern = "\((\d+(\.\d+)?)\)"
in diese:
.Pattern = "\((\d+(\,\d+)?)\)"
geändert und dann funktioniert alles perfekt.

Noch mall vielen, vielen Dank.
Schöne Grüße

Wojtek
This comment was minimized by the moderator on the site
...ich meinte addieren Dezimalbruche 🙂
This comment was minimized by the moderator on the site
Hi, Wojtek, if you just want to sum the decimal numbers only, try this code:
Function SumBracket(Target As Range) As Double
'UpdatebyExtendoffice20221209
Dim xCell As Range
Dim xObjs As Object, xObj As Object
Dim xSum As Double
Dim xNum As Integer
On Error Resume Next
Application.Volatile
Set xObjs = CreateObject("VBScript.RegExp")
xSum = 0
With xObjs
    .Global = True
    .Pattern = "\((\d+(\.\d+)?)\)"

    For Each xCell In Target
      If xCell.Value <> "" Then
        For Each xObj In xObjs.Execute(xCell.Value)
            xSum = xSum + Val(xObj.submatches(0)) - Int(Val(xObj.submatches(0)))
        Next
      End If
    Next
End With
SumBracket = xSum
End Function
This comment was minimized by the moderator on the site
Hallo Sonnig,
vielen Dank für die schnelle Antwort 😀. Um die Ganze klar zu machen gebe ich ein Beispiel meiner Aufgabe:

a(5), b(2,5), c(0,25) = 7,75

wie gesagt, mit:

a(5), b(2), c(21) im eine Zelle funktioniert die erste Makro super.

Vielen Dank und schöne Grüße
Wojtek
This comment was minimized by the moderator on the site
Sorry, Wojtek, I do undestand Geman, I just translate your question by Google so that I do not get your question clearly. Could you give me more description, for example, the data structure, are they in a cell or in different cell, in a column or in a row, what result you want.
This comment was minimized by the moderator on the site
Hallo Sonnig,

noch mal vielen Dank für die Mühe.

Geht um Summe alle Zahlen die in der Klammer stehen...
Erste Zelle: 458/1(2,5), 458/2(11), 458/3(0,75)
Zweite Zelle: Summe von 2,5 und 11 und 0,75
alles was in der Klammer steht in der erste Zelle sollte summiert sein. das Ergebnis soll in der Zweite Zelle erscheinen.

Vielen Dank und schöne Grüße
Wojtek
This comment was minimized by the moderator on the site
Hallo,
danke, Makro funktioniert super, aber leider nur mit Ganze Zahl, nicht mit Bruchzahl. Wäre das möglich zu ändern?
This comment was minimized by the moderator on the site
I'm sorry, I meant adding the numbers outside the bracket.
This comment was minimized by the moderator on the site
Hi, Adduar, I do not find a formula to solve your problem, maybe you only can use the Extract Text tool of Kutools for Excel to extract the numbers first, and then sum them, the conditions are *( and )*.
This comment was minimized by the moderator on the site
How to add numbers within the bracket?
This comment was minimized by the moderator on the site
Hi, How do I modify the pattern to sum everything between F-( and )


Example of my data is: F-(10) F-(12) E-(8)


the sum would be 22


thanks
This comment was minimized by the moderator on the site
Hi, Andy, please try this code:
Function SumBracket(Target As Range) As Double
'UpdatebyExtendoffice20160901
Dim xCell As Range
Dim xObjs As Object, xObj As Object
Dim xSum As Double
Set xObjs = CreateObject("VBScript.RegExp")
xSum = 0
With xObjs
.Global = True
.Pattern = "\-\((\d+(\.\d+)?)\)"

For Each xCell In Target
If xCell.Value <> "" Then
For Each xObj In xObjs.Execute(xCell.Value)
xSum = xSum + xObj.submatches(0)
Next
End If
Next
End With
SumBracket = xSum
End Function
This comment was minimized by the moderator on the site
Hello, is there a Google App Script version of the VBA script. I would like to use it in Google Sheets.
Thanks. :D
This comment was minimized by the moderator on the site
Sorry I do not know
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations