ไปยังเนื้อหาหลัก

วิธีการรวมตัวเลขในวงเล็บเฉพาะใน 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),
จากนั้นลากที่จับเติมอัตโนมัติลงเพื่อดึงตัวเลขที่อยู่ในวงเล็บออกจากแต่ละเซลล์ ดูภาพหน้าจอ:
doc รวมตัวเลขในวงเล็บ 2

ปลาย: ในสูตร A1 คือเซลล์ที่คุณต้องการแยกตัวเลขภายในวงเล็บออกมา

2. เลือกเซลล์ที่คุณจะวางผลสรุปที่แล้วป้อน = SUM (B1: B8)และกด เข้าสู่ สำคัญ. ดูภาพหน้าจอ:
doc รวมตัวเลขในวงเล็บ 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

doc รวมตัวเลขในวงเล็บ 4

2. บันทึกรหัสและไปที่เลือกเซลล์ที่จะวางผลลัพธ์และป้อนสูตรนี้ = SumBracket (A1: A8)กด เข้าสู่ สำคัญ. ดูภาพหน้าจอ:
doc รวมตัวเลขในวงเล็บ 5


รวมตัวเลขภายในวงเล็บด้วย Kutools for Excel เท่านั้น

จริงๆแล้วด้วย Kutools สำหรับ Excel's แยกข้อความ เพื่อแยกตัวเลขภายในวงเล็บจากนั้นใช้ไฟล์ รวมค่าสัมบูรณ์ ฟังก์ชันเพื่อสรุปตัวเลข

Kutools สำหรับ Excel, ที่มีมากกว่า 300 ฟังก์ชั่นที่มีประโยชน์ทำให้งานของคุณง่ายขึ้น 

หลังจากการติดตั้ง Kutools สำหรับ Excel โปรดทำดังนี้ :(ดาวน์โหลด Kutools for Excel ได้ฟรีทันที!)

1. เลือกสตริงที่คุณต้องการแยกตัวเลขในวงเล็บแล้วคลิก คูทูลs> ข้อความ > แยกข้อความ. ดูภาพหน้าจอ:
doc รวมตัวเลขในวงเล็บ 6

2 ใน แยกข้อความ กล่องโต้ตอบป้อน (*) เข้าไปใน ข้อความ กล่องข้อความแล้วคลิก เพิ่ม เพื่อเพิ่มลงในไฟล์ แยกรายการ. จากนั้นคลิก Okและเพื่อเลือกเซลล์เพื่อวางตัวเลขที่แยกออกมาในกล่องโต้ตอบ popping เช่น C1 ดูภาพหน้าจอ:

หมายเหตุ หากมีกฎการแยกอื่น ๆ ในไฟล์ แยกรายการ โปรดยกเลิกการเลือกกฎการแยกข้อมูลเหล่านี้และตรวจสอบเฉพาะกฎการแยกข้อมูลใหม่ที่เพิ่มเข้ามาของ (*).


doc รวมตัวเลขในวงเล็บ 7 ลูกศรยิงไปทางขวา doc รวมตัวเลขในวงเล็บ 8

3 คลิก OKและตอนนี้ตัวเลขในวงเล็บจะถูกดึงออกมา ตามค่าเริ่มต้นตัวเลขภายในวงเล็บจะถูกรับรู้ว่าเป็นลบคุณต้องรวมค่าสัมบูรณ์
doc รวมตัวเลขในวงเล็บ 9

4. เลือกเซลล์ที่คุณจะวางผลการคำนวณคลิก Kutools > ตัวช่วยสูตร > คณิตศาสตร์และทริก > รวมค่าสัมบูรณ์. ดูภาพหน้าจอ:
doc รวมตัวเลขในวงเล็บ 10

5 ใน ตัวช่วยสูตร ให้เลือกช่วงที่มีตัวเลขที่แยกออกมา จำนวน textbox, C1: C8 ในกรณีนี้ คลิก Ok มีการเพิ่มค่าสัมบูรณ์ของตัวเลข ดูภาพหน้าจอ:

doc รวมตัวเลขในวงเล็บ 11 ลูกศรยิงไปทางขวา doc รวมตัวเลขในวงเล็บ 12

เคล็ดลับ หากคุณต้องการทดลองใช้ แยกข้อความ และ รวมค่าสัมบูรณ์s ฟังก์ชั่น โปรดไปดาวน์โหลด Kutools for Excel ฟรี ก่อนแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น

สุดยอดเครื่องมือเพิ่มผลผลิตในสำนักงาน

🤖 Kutools AI ผู้ช่วย: ปฏิวัติการวิเคราะห์ข้อมูลโดยยึดตาม: การดำเนินการที่ชาญฉลาด   |  สร้างรหัส  |  สร้างสูตรที่กำหนดเอง  |  วิเคราะห์ข้อมูลและสร้างแผนภูมิ  |  เรียกใช้ฟังก์ชัน Kutools...
คุณสมบัติยอดนิยม: ค้นหา เน้น หรือระบุรายการที่ซ้ำกัน   |  ลบแถวว่าง   |  รวมคอลัมน์หรือเซลล์โดยไม่สูญเสียข้อมูล   |   รอบโดยไม่มีสูตร ...
การค้นหาขั้นสูง: VLookup หลายเกณฑ์    VLookup หลายค่า  |   VLookup ข้ามหลายแผ่น   |   การค้นหาที่ไม่ชัดเจน ....
รายการแบบเลื่อนลงขั้นสูง: สร้างรายการแบบหล่นลงอย่างรวดเร็ว   |  รายการแบบหล่นลงขึ้นอยู่กับ   |  เลือกหลายรายการแบบหล่นลง ....
ผู้จัดการคอลัมน์: เพิ่มจำนวนคอลัมน์เฉพาะ  |  ย้ายคอลัมน์  |  สลับสถานะการมองเห็นของคอลัมน์ที่ซ่อนอยู่  |  เปรียบเทียบช่วงและคอลัมน์ ...
คุณสมบัติเด่น: กริดโฟกัส   |  มุมมองการออกแบบ   |   บาร์สูตรใหญ่    สมุดงานและตัวจัดการชีต   |  ห้องสมุดทรัพยากร (ข้อความอัตโนมัติ)   |  เลือกวันที่   |  รวมแผ่นงาน   |  เข้ารหัส/ถอดรหัสเซลล์    ส่งอีเมลตามรายการ   |  ซุปเปอร์ฟิลเตอร์   |   ตัวกรองพิเศษ (กรองตัวหนา/ตัวเอียง/ขีดทับ...) ...
ชุดเครื่องมือ 15 อันดับแรก12 ข้อความ เครื่องมือ (เพิ่มข้อความ, ลบอักขระ, ... )   |   50 + แผนภูมิ ประเภท (แผนภูมิ Gantt, ... )   |   40+ ใช้งานได้จริง สูตร (คำนวณอายุตามวันเกิด, ... )   |   19 การแทรก เครื่องมือ (ใส่ QR Code, แทรกรูปภาพจากเส้นทาง, ... )   |   12 การแปลง เครื่องมือ (ตัวเลขเป็นคำ, การแปลงสกุลเงิน, ... )   |   7 ผสานและแยก เครื่องมือ (แถวรวมขั้นสูง, แยกเซลล์, ... )   |   ... และอื่น ๆ

เพิ่มพูนทักษะ Excel ของคุณด้วย Kutools สำหรับ Excel และสัมผัสประสิทธิภาพอย่างที่ไม่เคยมีมาก่อน Kutools สำหรับ Excel เสนอคุณสมบัติขั้นสูงมากกว่า 300 รายการเพื่อเพิ่มประสิทธิภาพและประหยัดเวลา  คลิกที่นี่เพื่อรับคุณสมบัติที่คุณต้องการมากที่สุด...

รายละเอียด


แท็บ Office นำอินเทอร์เฟซแบบแท็บมาที่ Office และทำให้งานของคุณง่ายขึ้นมาก

  • เปิดใช้งานการแก้ไขและอ่านแบบแท็บใน Word, Excel, PowerPoint, ผู้จัดพิมพ์, Access, 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