简体   繁体   English

仅在 B 列中插入一行

[英]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.

相关问题 在A列中查找值X的行,并在B列的同一行中插入值Y - Finding row of value X in column A, and inserting value Y in the same row, in column B 如果 A 列在 B 列中只有 1 个匹配变量,则突出显示行 - Highlight row if column A has ONLY 1 matching variable in column B VBA循环发生条件:仅当此行中的列A为空时,才使用列B的值 - VBA Loop on condition: use value of column B only if Column A in this row is empty 如果 B 列不为空且行为偶数,则为行着色 - Color a row if column B is not blank and row is even 仅当同一行的 B 列是同类中的第一个且 A 列小于指定值时,才计算 A 列的公式或方法(在 excel 中)? - Formula or way (in excel) to count column A only if column B of the same row is the first of it's kind and column A is less then a specified value? 在每行之前插入一列并复制标题 - Inserting a column before every row and copying header 在整个行中从Excel列插入数据 - Inserting Data From a Excel Column Throughout the Row 将userform值插入特定列中的活动行 - Inserting a userform value to the active row in a specific column 将工作簿中每个工作表的 A1 中的值插入目录的 B 列 - Inserting the value in A1 of each worksheet in the WorkBook into column B of the Table of Contents 如果B列中有重复项,则删除整行 - Delete whole row if there is duplication in column B
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM