跳到主要内容

如何从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()
应用程序.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 =真
END SUB


一键删除表中所有空行和列

Kutools for Word 为您提供了从文档表格中删除所有空行和空列的最方便的方法。您只需点击一次,然后 Kutools for Word Delete Rows/Columns 实用程序将为您快速从所有或选择的表中删除所有空行和列。

Kutools for Word, 与超过  方便的功能,使您的工作更加轻松。 

安装后 Kutools for Word,请执行以下操作:(立即免费下载 Kutools for Word!)

1。 点击 Kutools 加 > Delete Rows/ColumnsTable 窗格。

doc从表1删除空白行列

2.然后弹出一个对话框,在“查找范围”部分中选择要从中删除表的范围,然后检查 选项和 空白行 选项或检查 选项和 空白行 您需要的选项。 如果要删除所有空白行和列,则需要两次应用此操作。

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

现在会弹出一个对话框,提醒您已处理了多少张表,请单击 OK 关闭,并且空白行和列已从表中删除。
doc kutools删除空白行4

小费。如果要从Excel工作表中删除空白行,则 删除空白行 Kutools for Excel 的实用程序可以帮助你。

最佳办公生产力工具

Kutools for Word - 通过 Over 提升您的文字体验 100 显着特点!

深入了解下面突出显示的功能或 单击此处探索 Kutools for Word 的全部功能.

📘 文档掌握: 分页  /  合并文件  /  以各种格式导出选择(PDF/TXT/DOC/XLSX)  /  批量转换为PDF  /  将页面导出为图像  /  一次打印多个文件 ...

内容编辑: 批量查找和替换 跨多个文件   /  调整所有图片的大小   /  转置表行和列  /  将表格转换为文字 ...

🧹 轻松清洁扫开 多余的空间  /  分节符  /   所有标题  /  文本框  /  超链接  /  如需更多删除工具,请前往我们的删除组

创意插入: 插页 千位分隔符  /  复选框  /  单选按钮  /  二维码  /  条码  /  对角线表  /  公式标题  /  图片说明  /  表标题  /  多张图片  /  在我们的插入组中发现更多信息

🔍 精准选择: 精确定位特定页面  /    /  形状  /  标题段落  /  使用我们的选择组轻松导航

星级增强: 快速导航至任何位置  /  自动插入重复文本  /  在文档窗口之间无缝切换  /  11 转换工具 ...

使用 Kutools 转换您的 Word 任务。 👉 立即下载并试用 30 天 🚀。

了解更多       免费下载      购买
 
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