[英]Inserting a row into only column B
I've written a macro to copy a row from Sheet 2 and inset that row into Sheet 1. My problem is that I only wish to insert the row starting at Column B on the active row.我已经编写了一个宏来从 Sheet 2 复制一行并将该行插入到 Sheet 1 中。我的问题是我只希望从活动行的 B 列开始插入行。 Here is the macro:这是宏:
Sub addTestProductRow()
Sheets("Macro templates").Range("B2:J2").Copy
Selection.Insert Shift:=xlDown
End Sub
Currently my macro does this:目前我的宏是这样做的:
If the user has selected the cell K2 and executes the macro, the Row will be inserted from K2 to S2如果用户选择了单元格 K2 并执行了宏,则行将从 K2 插入到 S2
What I want the macro to do:我希望宏做什么:
If the user has selected cell K2 and executes the macro, the Row will be inserted from B2 to J2如果用户选择了单元格 K2 并执行宏,则行将从 B2 插入到 J2
Things to note: The row contains a check box so that has to be copied across, currently my macro does copy and paste the check box correctly.注意事项:该行包含一个复选框,因此必须复制,目前我的宏可以正确复制和粘贴复选框。
Change:改变:
Selection.Insert Shift:=xlDown
to:到:
Sheets("nameOfOtherSheetGoesHere").Range("B2").Insert Shift:=xlDown
Rather than relying on the selection, specify the sheet and range where you want the insert to take place与其依赖选择,不如指定您希望插入的工作表和范围
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.