简体   繁体   English

EXCEL VBA 尝试将数据从一个工作表上的非连续单元格复制到单独工作表上的下一个可用行

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

相关问题 Excel-VBA将数据从一个工作表复制到另一工作表并粘贴到新行 - Excel-VBA Copy data from one worksheet to another worksheet and paste in new row 使用Excel VBA将.msg文件中的粘贴表数据复制到Excel工作表中的单独单元格中 - Copy Paste table data from a .msg file into separate cells in an Excel worksheet using Excel VBA Excel VBA-通过循环将数据从一个工作表复制到另一个工作表 - Excel VBA - Copy data from one worksheet to another via loop Excel使用VBA将数据从一张纸复制到工作表上的另一张 - Excel copy data from one sheet to another on worksheet refresh with vba Excel VBA:从一个工作表复制到另一个 - Excel VBA: Copy from one worksheet to another Excel VBA复制/粘贴范围到另一个工作表中的下一个可用单元格 - Excel VBA Copy/Paste Range to the next available cell in another worksheet 如何创建宏以将数据从一个Excel工作表复制到另一个工作表中的下一行 - How to create a macro to copy data from one excel worksheet to the next line in another worksheet VBA代码可从一个工作表复制数据并将其粘贴到另一工作表的最后一行下方 - VBA code to copy data from one worksheet & paste below last row of another worksheet 复制工作表excel VBA进行微调。 从某些单元格复制,粘贴在某些单元格和工作表中, - copy worksheet excel VBA fine tuning. Copy from certain cells, paste in certain cells & worksheet naming, 将行复制到新工作表到下一个可用行 - copy row to new worksheet to next available row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM