[英]EXCEL VBA Trying to copy data from non consecutive cells on one worksheet to the next available row on separate worksheet
I am very new to all this and have been taking bits from here and there on various excel websites and have managed to get most of what i need working macro-wise.我对这一切都很陌生,并且一直在各种 excel 网站上从这里和那里获取一些信息,并设法从宏观上获得了我需要的大部分内容。 But this one has me stumped..但这个让我难倒..
I have an order from on a worksheet labeled "Order Form" that is filled in by my colleagues for each new order, i need them to be able to click a button and then all the data they have filled in will be copied to another worksheet labeled "Orders".我的同事为每个新订单填写了一个标有“订单表”的工作表上的订单,我需要他们能够单击一个按钮,然后他们填写的所有数据都将被复制到另一个工作表标记为“订单”。 I have managed to get the data copied but the best i could get was the data pasted into the exact same cells on the "Orders" worksheet.我设法复制了数据,但我能得到的最好的结果是将数据粘贴到“订单”工作表上完全相同的单元格中。
Heres what i have code wise this works for copying...这是我的代码明智的,这适用于复制...
Dim copyRng As Range, cel As Range, _
pasteRng As Range
Set copyRng = ThisWorkbook.Sheets("Order Form").Range("B3,F3,C10,C11,C12,C13,C14,C15,D21,D22,D23,D24,D25,D26,D27,D28,D29,D30,D31,D32,D33,D34,E48,D36,G10,C40,G40")
Set pasteRng = ThisWorkbook.Sheets("Orders").Range("A2")
What i need is to paste the data that is copied above into the next blank row on the "orders" worksheet.我需要的是将上面复制的数据粘贴到“订单”工作表上的下一个空白行中。 I know that code is very messy and is probably overkill for copying those cells and its probably really simple to do but i cannot work it out... Please someone help its doing my head in lol我知道代码很乱,复制这些单元格可能有点矫枉过正,而且它可能真的很简单,但我无法解决......请有人帮助它在lol中做我的头脑
You can't copy and paste multiple selections.您不能复制和粘贴多个选择。 Quick and easy solution is to do one cell at a time.快速简便的解决方案是一次做一个单元格。
Dim pasterange As Long
pasterange = ThisWorkbook.Sheets("Orders").Range("A" & Rows.Count).End(xlUp).Row + 1 ' the plus 1 is to get the next blank row
ThisWorkbook.Sheets("Order Form").Range("B3").Copy Destination:=ThisWorkbook.Sheets("Orders").Range("A" & pasterange)
ThisWorkbook.Sheets("Order Form").Range("F3").Copy Destination:=ThisWorkbook.Sheets("Orders").Range("B" & pasterange)
ThisWorkbook.Sheets("Order Form").Range("C10").Copy Destination:=ThisWorkbook.Sheets("Orders").Range("C" & pasterange)
I would just copy and paste that down and add the additional cells you need copied and continue the A,B,C, etc in the destination portion.我只是复制并粘贴下来,然后添加您需要复制的其他单元格,然后在目标部分继续 A、B、C 等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.