VBA Excel - 在下面插入相同格式的行,包括边框和框架 [英] VBA Excel - Insert row below with same format including borders and frames
本文介绍了VBA Excel - 在下面插入相同格式的行,包括边框和框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想构建一个宏,它以相同的格式在所选单元格下方插入一行。这是迄今为止的代码:
I want to build a macro that inserts a row below the selected cell with the same format. This is the code I have so far:
Public Sub insertRowBelow()
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
End Sub
问题是:此代码仅部分转移格式。它对新行使用相同的背景颜色,但它不使用单元格的边框/框架。如何实现?
The problem is: This code only partially transfers the format. It does use the same background color for the new row, but it does not use the borders/frames for the cells. How can I achieve that?
推荐答案
最简单的选择是利用Excel复制/粘贴。
The easiest option is to make use of the Excel copy/paste.
Public Sub insertRowBelow()
ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove
ActiveCell.EntireRow.Copy
ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End Sub
这篇关于VBA Excel - 在下面插入相同格式的行,包括边框和框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文