跳到主要內容

如果單元格在Excel中包含零,如何刪除整行?

有時,如果在Excel中該單元格包含零,則希望刪除整行,如果其中有幾個,則可以將它們一一刪除。 但是,需要刪除幾百行包含零的行嗎? 您可以選擇以下一種棘手的方法來解決它。

如果單元格中包含零與Excel中的篩選器功能刪除行
如果Excel中的VBA單元格包含零,則刪除行
如果單元格包含零,則使用Kutools for Excel刪除行


如果單元格中包含零與Excel中的篩選器功能刪除行

您可以使用“過濾器”功能基於某一列中的零值過濾掉所有行,然後在以後刪除所有可見行。 請執行以下操作。

1.選擇包含要刪除其整個行的零值的列單元格,然後單擊 數據 > 篩選。 看截圖:

2.然後,在所選列的第一個單元格中顯示一個下拉箭頭,單擊箭頭,然後選擇 號碼過濾器 > 等於 從下拉列表中選擇。

doc如果為零則刪除1

3。 在裡面 自定義自動篩選 對話框中,輸入數字 0 進入文本框,如下圖所示,然後單擊 OK 按鈕。

doc如果為零則刪除1

4.然後,該特定列中的所有零值單元格將被過濾掉。 請選擇過濾器範圍內的所有可見單元格,然後右鍵單擊它們,選擇 刪除行 從右鍵單擊菜單中。 然後在彈出的提示框中,點擊 OK 按鈕。 看截圖:

doc如果為零則刪除1

5.現在,所有可見行均被刪除。 您可以點擊 數據 > 篩選 再次顯示所有沒有零值單元格的數據。 看截圖:

doc如果為零則刪除1


如果Excel中的某個範圍內存在零值,則輕鬆刪除所有行:

Kutools for Excel的 選擇特定的單元格 該實用程序可以幫助您輕鬆地選擇整個行(如果在某個範圍內存在零值),然後您可以手動快速快速刪除所有選定的行,而不會出現任何錯誤。
立即下載並嘗試! (30 天免費試用)


如果Excel中的VBA單元格包含零,則刪除行

本節將向您展示VBA方法,以刪除Excel中某一列中存在零值的所有行。

1。 按 Alt + F11鍵 同時顯示 Microsoft Visual Basic for Applications 窗口。

2.在“ Microsoft Visual Basic for Applications”窗口中,單擊“ 插入 > 模塊,然後將以下VBA代碼複製並粘貼到模塊窗口中。

VBA:如果工作表中的某些列範圍內存在零值,則刪除整個行

Sub DeleteZeroRow()'Updateby20140616 Dim Rng作為範圍Dim WorkRng作為錯誤發生時的範圍恢復下一個xTitleId =“ KutoolsforExcel” Set WorkRng = Application.Selection Set WorkRng = Application.InputBox(“ Range”,xTitleId,WorkRng.Address,類型:= 8 )Application.ScreenUpdating = False設置Rng = WorkRng.Find(“ 0”,LookIn:= xlValues)如果不是Rng則為空,則Rng.EntireRow.Delete結束,如果循環而不是Rng則為空Application.ScreenUpdating =真端

3。 按 F5 運行代碼的關鍵,在彈出窗口中 Kutoolsfor Excel 對話框中,根據其中的零值選擇要刪除整個行的列範圍,然後單擊 OK 按鈕。 看截圖:

doc如果為零則刪除1

然後,將立即刪除基於指定列範圍內零值的所有行。

doc如果為零則刪除1


如果單元格包含零,則使用Kutools for Excel刪除行

對於許多Excel用戶,使用VBA代碼在Excel中刪除數據很危險。 如果您不完全信任VBA代碼,我們建議您在此處嘗試 選擇特定的單元格 的效用 Excel的Kutools.

申請前 Excel的Kutools首先下載並安裝.

1.選擇列範圍,您將基於其中的零值刪除整個行,然後單擊 庫工具 > 選擇 > 選擇特定的單元格。 看截圖:

2。 在裡面 選擇特定的單元格 對話框,您需要:

(1)選擇 整行 在選項 選擇類型 部分。

(2)選擇 等於 在第一 特定類型 下拉列表,然後輸入數字 0 進入文本框。

(3)點擊 OK 按鈕。

3.彈出一個對話框,告訴您已選擇了多少行,單擊 OK 按鈕。 現在,所有具有零值的行都位於指定的列範圍內。 請右鍵單擊任何選定的行,然後單擊 刪除 在右鍵菜單中。 看截圖:

doc如果為零則刪除1

現在,指定列中存在的所有值為零的行將立即刪除。 看截圖:

doc如果為零則刪除1

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


如果單元格包含零,則使用Kutools for Excel刪除行


相關文章:

最佳辦公生產力工具

熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

kte選項卡201905


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 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