跳到主要內容

如何從Word中的表中刪除空的行和列?

如何從Word中的表中刪除所有空行和列? 本教程將向您展示幾種從Word文檔中的表中刪除空行和列的方法。

手動刪除表中所有空行和列

使用VBA代碼從表中刪除所有空行和列

一鍵刪除表中所有空行和列好主意3


手動刪除表中所有空行和列

Microsoft Office Word不提供刪除空行和空列的便捷方法,您需要通過手動選擇每個空行和空列然後逐個刪除它們來刪除它們。

步驟1:選擇要刪除的空行或空列。 看截圖:

文檔-removerowsandcols-1

步驟3:下 枱燈 工具,點擊 佈局 標籤;

文檔-removerowsandcols-2

步驟4:在 行和列 組,單擊 刪除行 或刪除列.

文檔-removerowsandcols-3


使用VBA代碼從表中刪除所有空行和列

Word的宏功能提供了一種更為方便的方法,可從文檔表中刪除所有空行和列。 您可以按以下步驟刪除所有空行和列。

步驟1:按 “ Alt-F11” 打開“ Microsoft Visual Basic應用程序”窗口;

步驟2:點擊 模塊 插入 選項卡,將以下VBA代碼複製並粘貼到“模塊”窗口中;

步驟3:然後點擊 文檔反向符號 6 按鈕以應用VBA。

VBA代碼從表中刪除所有空行和列:

子DeleteEmptyTablerowsandcolumns()
Application.ScreenUpdating = False
Dim Tbl如表,cel如單元格,i長,n長,fEmpty為布爾值
使用ActiveDocument
對於.Tables中的每個Tbl
n = Tbl.Columns.Count
對於i = n至1步驟-1
fEmpty =真
對於Tbl.Columns(i).Cells中的每個cel
如果Len(cel.Range.Text)> 2然後
fEmpty =假
退出
如果結束
下一個
如果fEmpty = True,則Tbl.Columns(i).Delete
接下來,我
下一個Tbl
結束
使用ActiveDocument
對於.Tables中的每個Tbl
n = Tbl.Rows.Count
對於i = n至1步驟-1
fEmpty =真
對於Tbl.Rows(i).Cells中的每個cel
如果Len(cel.Range.Text)> 2然後
fEmpty =假
退出
如果結束
下一個
如果fEmpty = True,則Tbl.Rows(i).Delete
接下來,我
下一個Tbl
結束
設置cel =否:設置Tbl =否
Application.ScreenUpdating = True
END SUB


一鍵刪除表中所有空行和列

Kutools for Word提供了最方便的方法來從文檔表中刪除所有空行和列。 您只需要單擊一次,然後 Kutools for Word Delete Rows/Columns 實用程序將為您快速從所有或選擇的表中刪除所有空行和列。

Kutools for Word, 與以上  方便的功能,使您的工作更加輕鬆。 

安裝後 Kutools for Word,請執行以下操作:(現在免費下載Kutools for Word!)

1。 點擊 Kutools 加 > Delete Rows/Columns Table 窗格。

doc從表1刪除空白行列

2.然後彈出一個對話框,在“查找範圍”部分中選擇要從中刪除表的範圍,然後檢查 選項和 空白行 選項或檢查 選項和 空白行 您需要的選項。 如果要刪除所有空白行和列,則需要兩次應用此操作。

doc kutools刪除空白行2  doc kutools刪除空白行3 

現在會彈出一個對話框,提醒您已處理了多少張表,請單擊 OK 關閉,並且空白行和列已從表中刪除。
doc kutools刪除空白行4

小費。如果要從Excel工作表中刪除空白行,則 刪除空白行 Kutools for Excel實用程序可以為您提供幫助。

最佳辦公生產力工具

Kutools for Word - 透過 Over 提升您的文字體驗 100 顯著特點!

🤖 Kutools 人工智慧助手:用人工智慧改變你的寫作 - 生成內容  /  重寫文字  /  總結文件  /  查詢資料 基於文檔,全部在Word中

📘 文件掌握: 分頁  /  合併文件  /  以各種格式匯出選擇(PDF/TXT/DOC/HTML...)  /  批次轉換為PDF  /  將頁面匯出為圖像  /  一次列印多個文件...

內容編輯: 批量查找和替換 跨多個文件  /  調整所有圖片的大小  /  轉置表行和列  /  將表格轉換為文字...

🧹 輕鬆清潔: 移開 多餘的空間  /  分節符  /  所有標題  /  文本框  /  超鏈接  / 如需更多拆卸工具,請前往我們的 刪除組...

創意插入: 插入 千位分隔符  /  複選框  /  單選按鈕  /  QR Code  /  條碼  /  對角線表  /  公式標題  /  圖片說明  /  表格標題  /  多張圖片  / 發現更多 插入組...

🔍 精準選擇:精確定位 特定頁面  /    /  形狀  /  標題段落  / 增強導航功能 更多 選擇功能...

星級增強: 快速導航至任何位置  /  自動插入重複文字  /  在文檔視窗之間無縫切換  /  11 轉換工具...

???? 想嘗試這些功能嗎? Kutools for Word 提供了 60天免費試用,沒有任何限制! 🚀
 
Comments (16)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi
Many many thanks. Its 100% worked.
This comment was minimized by the moderator on the site
Hi, thanks for the CODE, it worked on a document with only one table.

but when launching it on a word document with different tables from different sizes, i got this error : "Run-time error '5992' Cannot access individual columns in this collection because the table has mixed cell widths"

Can anybody help, please
This comment was minimized by the moderator on the site
Bonjour,

Quand j'exécute le programme, l'erreur suivante s'affiche " Erreur de compilation : Instruction incorrecte à l'extérieur d'une procédure"

Quelqu'un a une solution s'il vous plait ?
This comment was minimized by the moderator on the site
I found this macro and it works great when it comes to a table with single empty rows.
Is it possible to change it to work on a table with split rows as well?
I would very much thank you if you have a solution for me.
This comment was minimized by the moderator on the site
Hi, shimon, I don't not understand your question, please give me examples or describe the question with more details.
This comment was minimized by the moderator on the site
You just saved me a zillion hours of frustration, THANK YOU!
This comment was minimized by the moderator on the site
u know you can just resize the table right? just filter and sort your data to top check how many rows have data, click table tools and the click resize and adjust the last number to whatever you need OR go to the bottom of the table the very last cell and use the tine blue triangle to drag and resize,
This comment was minimized by the moderator on the site
Except I have multiple page document with a table with varying information in each. Furthermore, it is a merge document so different each week. I need an automated method :)
This comment was minimized by the moderator on the site
Hi, the macro is working, BUT:

After deleting all rows, all the columns of the tables with empty rows open up very wide.

How can i fix the code so that this does not happens?


I am using Office 2016.


Thank you!
This comment was minimized by the moderator on the site
Hi All, I am looking for function in word wherein, if I remove specific word then it should remove that row as well.
This comment was minimized by the moderator on the site
Thanks for the code, really useful.
This comment was minimized by the moderator on the site
Is there a macro that will delete a row if only one of the cells in that row is empty or contains a zero?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations