excel vba插入带格式的行 [英] excel vba insert row with formatting

查看:21
本文介绍了excel vba插入带格式的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏,它根据 Excel 2007 中的用户输入插入多行.一切正常,但我仍然有一个小问题.我想从上面的行中复制完整的格式.它仅适用于行中的某些单元格.

I have a macro which inserts a number of rows depending on user input in Excel 2007. Everything works but I still have a minor issue. I want to copy the complete formatting from the row above. It only works for some cells in the row.

下面是插入代码:

 Rows("B:B").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

可以改吗?

最好的,美国

推荐答案

我不确定您是如何插入行的,但是如果您在现有行下方插入行,默认情况下它将采用行,至少当您使用这种类型的语法时它会这样做:

I am not sure exactly how you are inserting your rows, but if you insert the row below an existing one, it will by default take on the formatting of the row above it, at least it does when you use this type of syntax:

Range("B2").EntireRow.Offset(1, 0).Insert

在此示例中,它将在 B2 下方插入一行,并且格式(例如,B2 的行以黄色突出显示)也将是黄色的.这可能与这种插入类型确切地指定了要插入的行的事实有关.

In this example, it will insert a row below B2 and the format (say, B2's row is highlighted yellow) will be yellow as well. It might have to do with the fact that this type of inserting specifies exactly under which row to insert.

这篇关于excel vba插入带格式的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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