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

วิธีการนับ / รวมเซลล์ขีดทับใน Excel

ใน Excel เราจัดรูปแบบขีดทับสำหรับเซลล์บางเซลล์ซึ่งบ่งชี้ว่าค่าของเซลล์นั้นไม่มีประโยชน์หรือไม่ถูกต้องเพื่อให้เราสามารถวิเคราะห์ข้อมูลได้แม่นยำยิ่งขึ้น ในบทความนี้ฉันจะพูดถึงวิธีการคำนวณบางส่วนในช่วงด้วยเซลล์ขีดทับเหล่านี้ใน Excel

นับเซลล์ขีดทับใน Excel

นับโดยไม่มีเซลล์ขีดทับใน Excel

รวมไม่รวมเซลล์ขีดทับใน Excel


ลูกศรสีฟ้าฟองขวา นับเซลล์ขีดทับใน Excel

หากคุณต้องการทราบจำนวนเซลล์ที่มีรูปแบบขีดฆ่าในช่วงคุณสามารถสร้างฟังก์ชันที่กำหนดโดยผู้ใช้โปรดทำตามขั้นตอนต่อไปนี้:

1. กด ALT + F11 คีย์เพื่อเปิด หน้าต่าง Microsoft Visual Basic for Applications.

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ หน้าต่างโมดูล.

รหัส VBA: นับเซลล์ที่ขีดทับ

Public Function CountStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If pRng.Font.Strikethrough Then
        xOut = xOut + 1
    End If
Next
CountStrike = xOut
End Function

3. จากนั้นบันทึกและปิดรหัสนี้และกลับไปที่แผ่นงานจากนั้นป้อนสูตรนี้ = CountStrike (A2: B14) ไปยังเซลล์ว่างดูภาพหน้าจอ:

doc-นับ-นัดหยุดงาน-1

4. จากนั้นกด เข้าสู่ คีย์และนับเซลล์ขีดฆ่าทั้งหมดแล้ว ดูภาพหน้าจอ:

doc-นับ-นัดหยุดงาน-1


ลูกศรสีฟ้าฟองขวา นับโดยไม่มีเซลล์ขีดทับใน Excel

แต่บางครั้งคุณอาจต้องการนับจำนวนเฉพาะเซลล์ปกติซึ่งไม่รวมเซลล์ขีดฆ่า รหัสต่อไปนี้สามารถช่วยคุณได้

1. กด ALT + F11 คีย์เพื่อเปิด หน้าต่าง Microsoft Visual Basic for Applications.

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ หน้าต่างโมดูล.

รหัส VBA: นับโดยไม่มีเซลล์ขีดทับ

Public Function CountNoStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If Not pRng.Font.Strikethrough Then
        xOut = xOut + 1
    End If
Next
CountNoStrike = xOut
End Function

3. จากนั้นบันทึกและปิดรหัสนี้กลับไปที่แผ่นงานของคุณพิมพ์สูตรนี้ = countnostrike (A2: B14) ลงในเซลล์ว่างแล้วกด เข้าสู่ จากนั้นคุณจะได้ผลลัพธ์ที่คุณต้องการ

doc-นับ-นัดหยุดงาน-1

หมายเหตุ: ในสูตรข้างต้น A2: B14 คือช่วงที่คุณต้องการใช้สูตร


ลูกศรสีฟ้าฟองขวา รวมไม่รวมเซลล์ขีดทับใน Excel

เนื่องจากไม่ได้ใช้เซลล์ขีดทับที่นี่ฉันต้องการรวมเฉพาะตัวเลขปกติที่ไม่มีตัวเลขขีดทับ ในการแก้ปัญหานี้คุณต้องมีฟังก์ชันที่กำหนดโดยผู้ใช้

1. กด ALT + F11 คีย์เพื่อเปิด หน้าต่าง Microsoft Visual Basic for Applications.

2. คลิก สิ่งที่ใส่เข้าไป > โมดูลและวางรหัสต่อไปนี้ในไฟล์ หน้าต่างโมดูล.

รหัส VBA: ผลรวมไม่รวมเซลล์ขีดทับ

Public Function ExcStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
    If Not pRng.Font.Strikethrough Then
        xOut = xOut + pRng.Value
    End If
Next
ExcStrike = xOut
End Function

3. จากนั้นบันทึกและปิดรหัสนี้กลับไปที่แผ่นงานของคุณพิมพ์สูตรนี้ = excstrike (B2: B14) ลงในเซลล์ว่างแล้วกด เข้าสู่ และคุณจะได้ผลรวมของตัวเลขทั้งหมดโดยไม่มีเซลล์ขีดทับ ดูภาพหน้าจอ:

doc-นับ-นัดหยุดงาน-1

หมายเหตุ: ในสูตรข้างต้น B2: B14 คือช่วงที่คุณต้องการรวมเซลล์โดยไม่มีรูปแบบขีดทับใน


บทความที่เกี่ยวข้อง:

วิธีการรวม / นับตัวเลขตัวหนาในช่วงของเซลล์ใน Excel

วิธีการนับและรวมเซลล์ตามสีพื้นหลังใน Excel

วิธีการนับ / รวมเซลล์ตามสีฟอนต์ใน 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 (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I want to ignore the cell from count where both type of text strike and non strike available by VBA
This comment was minimized by the moderator on the site
Great! I found a little bug here. The result doesn't actualize by itself. When I do changes on the sheet, the number doesn't changes. How can I fix it? Thanks
This comment was minimized by the moderator on the site
Hi. Great code for ignoring strikethrough text whilst summing. But, is it possible to filter the data and get a subtotal which still sums without the strike through text? Thanks
This comment was minimized by the moderator on the site
This seems to round to whole numbers, and does not take into account the decimal places. For example, 1.35 + 1.00 would equal 2 instead of 2.35, but 1.50 + 1 would equal 3 instead of 2.50. How can you fix the code to add accurately?
This comment was minimized by the moderator on the site
[quote]This seems to round to whole numbers, and does not take into account the decimal places. For example, 1.35 + 1.00 would equal 2 instead of 2.35, but 1.50 + 1 would equal 3 instead of 2.50. How can you fix the code to add accurately?By Ari[/quote] ARI, just change the two words "Long" to "Double" in the formula. Here is the same formula above, with the correct Data Types to allow for values with decimal points: Public Function ExcStrike(pWorkRng As Range) As Double 'Update 20161107_IITCSglobal.com Application.Volatile Dim pRng As Range Dim xOut As Double xOut = 0 For Each pRng In pWorkRng If Not pRng.Font.Strikethrough Then xOut = xOut + pRng.Value End If Next ExcStrike = xOut End Function
This comment was minimized by the moderator on the site
Thank you very much for this information, it's extremely helpful, However, I'm having an issue using the VBA code: Sum exclude strikethrough cells.

It does not exclude the strikethrough cells in my table unless I manually perform a strikethrough then double click the cell for the code to work.

I'm using a table with a conditional format to shade and strikethrough the entire row when (Table Header called Sold) Column "W" cell contains a "Yes", then that row will have a strikethrough and grey color. The worksheet table is "InventoryItems" and is configured to calculated automatically, but the code is not being triggered to exclude the dollar amount when the cell contains the strikethrough. Could you advise what I might be doing wrong?
Thank you for your time and help.

There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations