我想要实现的是从选择中的特定列复制数据,并通过命令按钮将其粘贴到其他工作表的特定列。
示例:
我从工作表(“ ND”)中选择了范围(“ A2:K2”),我想从(A2,B2,D2,E2和H2)复制数据,并将其粘贴到工作表中( “ EC”)分别位于范围(A2,C2,B2,E2和G2)上。
任何答案将不胜感激!
答案 0 :(得分:0)
目标范围内是否有错字?还是您真的要在“ ADMIN_OF_GROUP
”中切换C2
和B2
?
您的安排最简单的答案是:
EC
以此类推。
希望有帮助
编辑
您必须在目标表中查找第一个空行
worksheets("EC").cells(2,1).Value = worksheets("ND").Cells(2,1).Value
直到找到添加新数据的空行。 使用@ simon-li中的代码,您需要编写:
dim targetRow as Integer
targetRow = 2
do until isEmpty(Worksheets("ND").Cells(targetRow,1).Value)
targetRow = targetRow +1
Loop
以此类推
编辑2
带有其他代码,它应该看起来像这样(最后是我的脑袋,检查了错误的表)
.Cells(targetRow, "A").Value = Worksheets("ND").Cells(rn, "A").Value
答案 1 :(得分:0)
在下面尝试此代码:
Sub test2()
Dim rn As Integer
rn = Selection.Row
With Worksheets("EC")
.Cells(rn, "A").Value = Worksheets("ND").Cells(rn, "A").Value
.Cells(rn, "C").Value = Worksheets("ND").Cells(rn, "B").Value
.Cells(rn, "B").Value = Worksheets("ND").Cells(rn, "D").Value
.Cells(rn, "E").Value = Worksheets("ND").Cells(rn, "E").Value
.Cells(rn, "G").Value = Worksheets("ND").Cells(rn, "H").Value
End With
End Sub
第二个问题:
Sub test2()
Dim rn As Integer
rn = Selection.Row
Dim targetRow As Integer
targetRow = 1
Do Until IsEmpty(Worksheets("EC").Cells(targetRow, 1).Value)
targetRow = targetRow + 1
Loop
With Worksheets("EC")
.Cells(targetRow, "A").Value = Worksheets("ND").Cells(rn, "A").Value
.Cells(targetRow, "C").Value = Worksheets("ND").Cells(rn, "B").Value
.Cells(targetRow, "B").Value = Worksheets("ND").Cells(rn, "D").Value
.Cells(targetRow, "E").Value = Worksheets("ND").Cells(rn, "E").Value
.Cells(targetRow, "G").Value = Worksheets("ND").Cells(rn, "H").Value
End With
End Sub