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

จะลบแถวทั้งหมดได้อย่างไรถ้าเซลล์มีศูนย์ใน Excel

บางครั้งคุณต้องการลบทั้งแถวหากเซลล์มีศูนย์ใน Excel และคุณสามารถลบทีละแถวได้หากมีไม่กี่แถว แต่จำเป็นต้องลบแถวหลายร้อยแถวที่มีศูนย์ออกอย่างไร? คุณสามารถเลือกวิธีที่ยุ่งยากด้านล่างเพื่อแก้ปัญหา

ลบแถวถ้าเซลล์มีศูนย์ด้วยฟังก์ชันตัวกรองใน Excel
ลบแถวถ้าเซลล์มีศูนย์ด้วย VBA ใน Excel
ลบแถวถ้าเซลล์มีศูนย์ด้วย Kutools for Excel


ลบแถวถ้าเซลล์มีศูนย์ด้วยฟังก์ชันตัวกรองใน Excel

คุณสามารถใช้ฟังก์ชันตัวกรองเพื่อกรองแถวทั้งหมดโดยยึดตามค่าศูนย์ในคอลัมน์ใดคอลัมน์หนึ่งจากนั้นจึงลบแถวที่มองเห็นทั้งหมดในภายหลัง กรุณาดำเนินการดังนี้

1. เลือกเซลล์คอลัมน์ที่มีค่าศูนย์ที่คุณต้องการลบทั้งแถวตามจากนั้นคลิก ข้อมูล > ตัวกรอง. ดูภาพหน้าจอ:

2. จากนั้นลูกศรดรอปดาวน์จะแสดงในเซลล์แรกของคอลัมน์ที่เลือกคลิกลูกศรจากนั้นเลือก ตัวกรองตัวเลข > เท่ากับ จากรายการแบบหล่นลง

doc ลบถ้าเป็นศูนย์ 1

3 ใน ตัวกรองอัตโนมัติที่กำหนดเอง กล่องโต้ตอบป้อนหมายเลข 0 ลงในช่องข้อความตามภาพด้านล่างที่แสดงจากนั้นคลิกที่ไฟล์ OK ปุ่ม

doc ลบถ้าเป็นศูนย์ 1

4. จากนั้นเซลล์ค่าศูนย์ทั้งหมดในคอลัมน์บางคอลัมน์นี้จะถูกกรองออก โปรดเลือกเซลล์ที่มองเห็นได้ทั้งหมดในช่วงตัวกรองและคลิกขวาที่เซลล์เหล่านั้นเลือก ลบแถว จากเมนูคลิกขวา และในกล่องพรอมต์ป๊อปอัพให้คลิกไฟล์ OK ปุ่ม. ดูภาพหน้าจอ:

doc ลบถ้าเป็นศูนย์ 1

5. ตอนนี้แถวที่มองเห็นทั้งหมดจะถูกลบ คุณสามารถคลิก ข้อมูล > ตัวกรอง อีกครั้งเพื่อแสดงข้อมูลทั้งหมดโดยไม่มีเซลล์ค่าเป็นศูนย์ ดูภาพหน้าจอ:

doc ลบถ้าเป็นศูนย์ 1


ลบแถวทั้งหมดได้อย่างง่ายดายหากมีค่าเป็นศูนย์ในช่วงหนึ่งใน Excel:

Kutools สำหรับ Excel's เลือกเซลล์เฉพาะ ยูทิลิตี้ช่วยให้คุณเลือกแถวทั้งหมดได้อย่างง่ายดายหากมีค่าศูนย์อยู่ในช่วงหนึ่งจากนั้นคุณสามารถลบแถวที่เลือกทั้งหมดด้วยตนเองได้อย่างรวดเร็วโดยไม่ผิดพลาด
ดาวน์โหลดและทดลองใช้ทันที! (เส้นทางฟรี 30 วัน)


ลบแถวถ้าเซลล์มีศูนย์ด้วย VBA ใน Excel

ส่วนนี้จะแสดงวิธี VBA เพื่อลบแถวทั้งหมดหากมีค่าเป็นศูนย์ในคอลัมน์ใดคอลัมน์หนึ่งใน Excel

1 กด Alt + F11 พร้อมกันเพื่อแสดงไฟล์ Microsoft Visual Basic สำหรับแอปพลิเคชัน หน้าต่าง

2. ในหน้าต่าง Microsoft Visual Basic for Applications คลิก สิ่งที่ใส่เข้าไป > โมดูลจากนั้นคัดลอกและวางโค้ด VBA ต่อไปนี้ลงในหน้าต่างโมดูล

VBA: ลบทั้งแถวหากมีค่าเป็นศูนย์ในช่วงคอลัมน์บางช่วงในแผ่นงาน

Sub DeleteZeroRow () 'Updateby20140616 Dim Rng As Range Dim WorkRng เป็น Range On Error Resume ถัดไป xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox ("Range", xTitleId, WorkRng.Address, Type: = 8 ) Application.ScreenUpdating = False Do Set Rng = WorkRng.Find ("0", LookIn: = xlValues) If Not Rng Is nothing then Rng.EntireRow.Delete End If Loop while Not Rng Is Nothing Application.ScreenUpdating = True End Sub

3 กด F5 คีย์เพื่อเรียกใช้รหัสในป๊อปอัป KutoolsforExcel กล่องโต้ตอบเลือกช่วงคอลัมน์ที่คุณต้องการลบทั้งแถวโดยยึดตามค่าศูนย์ภายในจากนั้นคลิกไฟล์ OK ปุ่ม. ดูภาพหน้าจอ:

doc ลบถ้าเป็นศูนย์ 1

จากนั้นแถวทั้งหมดที่ยึดตามค่าศูนย์ในช่วงคอลัมน์ที่ระบุจะถูกลบทันที

doc ลบถ้าเป็นศูนย์ 1


ลบแถวถ้าเซลล์มีศูนย์ด้วย Kutools for Excel

สำหรับผู้ใช้ Excel จำนวนมากการใช้รหัส VBA เป็นอันตรายต่อการลบข้อมูลใน Excel หากคุณไม่เชื่อถือรหัส VBA เราขอแนะนำให้คุณลองใช้ไฟล์ เลือกเซลล์เฉพาะ ประโยชน์ของ Kutools สำหรับ Excel.

ก่อนที่จะใช้ Kutools สำหรับ Excelโปรด ดาวน์โหลดและติดตั้งในตอนแรก.

1. เลือกช่วงคอลัมน์ที่คุณจะลบแถวทั้งหมดตามค่าศูนย์ภายในจากนั้นคลิก Kutools > เลือก > เลือกเซลล์เฉพาะ. ดูภาพหน้าจอ:

2 ใน เลือกเซลล์เฉพาะ คุณต้อง:

(1) เลือกไฟล์ ทั้งแถว ตัวเลือกใน ประเภทการเลือก มาตรา.

(2) เลือก เท่ากับ ในครั้งแรก ประเภทเฉพาะ รายการแบบเลื่อนลงจากนั้นป้อนหมายเลข 0 ลงในกล่องข้อความ

(3) คลิกไฟล์ OK ปุ่ม

3. กล่องโต้ตอบจะปรากฏขึ้นเพื่อบอกจำนวนแถวที่เลือกคลิกที่ OK ปุ่ม. ตอนนี้แถวทั้งหมดที่มีค่าเป็นศูนย์มีอยู่ในช่วงคอลัมน์ที่ระบุจะถูกเลือก กรุณาคลิกขวาที่แถวที่เลือกจากนั้นคลิก ลบ ในเมนูคลิกขวา ดูภาพหน้าจอ:

doc ลบถ้าเป็นศูนย์ 1

ตอนนี้แถวทั้งหมดที่มีค่าเป็นศูนย์อยู่ในคอลัมน์ที่ระบุจะถูกลบทันที ดูภาพหน้าจอ:

doc ลบถ้าเป็นศูนย์ 1

  หากคุณต้องการทดลองใช้ยูทิลิตีนี้ฟรี (30 วัน) กรุณาคลิกเพื่อดาวน์โหลดแล้วไปใช้การดำเนินการตามขั้นตอนข้างต้น


ลบแถวถ้าเซลล์มีศูนย์ด้วย 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
Despues de utilizar subtotal Como hacer para eliminar las filas involucradas que en el subtotal es igual a 0?
This comment was minimized by the moderator on the site
Insert this in VB new module.
This is with InputBox to delete row which contains that word.

Attribute VB_Name = "FindDelRowByWord"
Sub FindDelRow()
'Updateby20140616
Dim Rng As Range
Dim WorkRng As Range
Dim xRep As String
On Error Resume Next
xTitleId = "ZOK Tools"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
xRep = Application.InputBox("word to delete Row:", "ZOK Tools", , , , , 2)
Application.ScreenUpdating = False
Do
Set Rng = WorkRng.Find(xRep, LookIn:=xlValues)
If Not Rng Is Nothing Then
Rng.EntireRow.Delete
End If
Loop While Not Rng Is Nothing
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
WHAT IF you have a big sheet, and there are rows you want to keep, and others rows that contain certain key words and delete those? the kutools work for me but for one key word that many rows have that key word, the rows were deleted, i just want to have multiple key words to do the same? does this work for the code above?
This comment was minimized by the moderator on the site
Good Day,
Kutools can deal with two key words at the same time. You need to enable its second condition with "And" or "Or". Hope I can help.
This comment was minimized by the moderator on the site
This didn't work for me. It changed all values in my chosen column and the adjacent column to zeros. I must be doing something wrong!
This comment was minimized by the moderator on the site
Hi Sheri,
The code works well in my case. Which Excel verson do you use?
This comment was minimized by the moderator on the site
Hi Crystal. I posted this two years ago so I’m guessing I figured it out. But thanks for the reply.
This comment was minimized by the moderator on the site
Hi dears , I need a code to hide the rows which have the value=0 on the column "N" in the sheet 1. The value of the column "N" will change when update the details on the Sheet 2. that's the time need to un-hide the row. is this possible to do this with Excel formula(without macro and Excel Filters).
This comment was minimized by the moderator on the site
modified for my purpose--thank you for your help: Sub DeleteZeroRow() Dim Rng As Range Dim WorkRng As Range On Error Resume Next xTitleId = "" Application.Calculation = xlManual MsgBox "Set the range you want to remove the unused 0 quantity rows from" Set WorkRng = Application.InputBox("Range", xTitleId, "FG93:FG500", Type:=8) Application.ScreenUpdating = False Sheets("ENTRY").Select Do Set Rng = WorkRng.Find("0", LookIn:=xlValues) If Not Rng Is Nothing Then Rng.EntireRow.Delete End If Loop While Not Rng Is Nothing Application.ScreenUpdating = True Range("FF92").Select Selection.End(xlDown).Select MsgBox "Removed 0's ROWS from column FG--calculating now--please wait" Application.Calculation = xlAutomatic End Sub
This comment was minimized by the moderator on the site
I modified the below code to work for me. This deleted every row in column C that had "Delete" in the cell of column C. Sub Delete_DeleteRows() Set WorkRng = Range("C2:C12000") Application.ScreenUpdating = False Do Set Rng = WorkRng.Find("Delete", LookIn:=xlValues) If Not Rng Is Nothing Then Rng.EntireRow.Delete End If Loop While Not Rng Is Nothing Application.ScreenUpdating = True End Sub
This comment was minimized by the moderator on the site
Hi,
its worked for me, thanks a lot.
if I have multiple sheets? how i can run the script 1 time for all the sheets?
This comment was minimized by the moderator on the site
thanks for the response, worked for me
This comment was minimized by the moderator on the site
I modified the above code to work for me. I wanted to delete every row that had "Delete" in row C. Sub Delete_DeleteRows() Set WorkRng = Range("C2:C12000") Application.ScreenUpdating = False Do Set Rng = WorkRng.Find("Delete", LookIn:=xlValues) If Not Rng Is Nothing Then Rng.EntireRow.Delete End If Loop While Not Rng Is Nothing Application.ScreenUpdating = True End Sub
This comment was minimized by the moderator on the site
Your VB code doesn't work. It deletes all rows with a Zero in the 10s position. I hope no one actually uses this as they will delete data...
This comment was minimized by the moderator on the site
This was a life saver!!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations