[英]Insert Copied Cells and Shift Cells down
Super new to VB macros. VB 宏的超级新手。 I have a title row with formatting that needs to be inserted periodically through my data.我有一个带有格式的标题行,需要通过我的数据定期插入。 So basically I need to insert a static row of cells that is always at the top of my data, periodically throughout the below data.所以基本上我需要插入一个 static 单元格行,它总是在我的数据的顶部,周期性地贯穿下面的数据。
How can I insert a static copied row of cells into any given row, and then shift the existing rows down?如何将 static 复制的单元格行插入任何给定行,然后将现有行向下移动?
Here is my attempt:这是我的尝试:
*Sub InsertTitles()
'
' InsertTitles Macro
'
' Keyboard Shortcut: Ctrl+Shift+V
'
ActiveCell.Range("A1:J1").Select
Selection.Copy
Selection.Insert Shift:=xlDown
End Sub*
replace your code with this.用这个替换你的代码。
Dim r As Range, n As Integer
n = ActiveCell.Row
Set r = Range("A" & n & ":J" & n)
r.Insert shift:=xlDown
r.Offset(-1, 0).Value = Range("A1: J1").Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.