从具有合并单元格的表中删除范围 [英] Deleting a range from a table with merged cells

查看:126
本文介绍了从具有合并单元格的表中删除范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我要完成的工作是:从表中删除光标从表中到表末的所有行.

Basically, what I'm trying to accomplish is this: Delete all rows from a table starting from where the cursor is in the table to the end of the table.

问题在于此表包含垂直合并的单元格,因此当我尝试执行以下操作时:

The problem is that this table contains vertically merged cells, so when I try to do something like this:

For i = Selection.Tables(1).Rows.Count To Selection.Cells(1).RowIndex Step -1
    Selection.Tables(1).Rows(i).Delete
Next

它抱怨无法访问单个行,因为该表包含垂直合并的单元格.

It complains that individual rows cannot be accessed because the table contains vertically merged cells.

我也尝试过先选择范围,然后删除选择.但是我不能正确地定义范围.它总是抱怨参数定义不正确.

I've also tried selecting the range first, and then deleting the selection. But I couldn't get the range definition right; it always complained that there was an improperly defined parameter.

推荐答案

使用VBA合并表单元是否只是让后面感到痛苦? Word似乎与列数和行数混淆了.对于水平或垂直合并的单元格的任意组合,跟随效果都非常可靠.

Aren't merged table cells just a pain in the rear with VBA? Word seems to get confused with the column and row count. The follow seems to be pretty robust with any combination of horizontally or vertically merged cells.

Sub DeleteRows()

    Selection.MoveDown Unit:=wdLine, Count:=(Selection.Tables(1).Rows.Count - Selection.Cells(1).RowIndex), Extend:=wdExtend
    Selection.Rows.Delete

End Sub

这篇关于从具有合并单元格的表中删除范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆