简体   繁体   English

根据单元格值将数据从一张表复制并粘贴到另一张表

[英]Copy and paste data from one sheet to another sheet(s) based on cell value

Hey guys I have a question as briefly stated on the title.嘿伙计们,我有一个问题,正如标题中简要说明的那样。 To be specific, I have orders everyday and I need to put them on different worksheets according to the column "delivery provider" and "channel".具体来说,我每天都有订单,我需要根据“交付提供商”和“渠道”列将它们放在不同的工作表上。 image description here图片说明在这里

I had created a userform before but I have to divide my data sheet into several sheets according to the del provider and channel, then with the code我之前创建了一个用户表单,但我必须根据 del 提供者和渠道将我的数据表分成几张表,然后使用代码

lr = sh1.Cells(Rows.Count, 1).End(xlUp).Row

sh1.Range("A2:A" & lr).Copy Destination:=sh2.Range("B2")

to copy and paste all the columns one by one to each sheet.将所有列一一复制并粘贴到每张纸上。

But actually I have many providers(6 or more) which makes it much time consuming.但实际上我有很多提供者(6 个或更多),这使得它非常耗时。

So my concern is how can I copy and paste them into the desired worksheets according to the 2 columns.所以我关心的是如何根据 2 列将它们复制并粘贴到所需的工作表中。

I came across and idea that I can CONST each column in "data" as source column, and CONST each column in "ems_by_sea" and others as target/destination colunm, then do the FOR/NEXT statement.我偶然发现我可以将“数据”中的每一列作为源列,并将“ems_by_sea”中的每一列和其他列作为目标/目标列,然后执行 FOR/NEXT 语句。 But I have no idea how to CONST at different worksheets...但我不知道如何在不同的工作表中使用 CONST ......

const firstrow = 2
const soucol_provider = sh1.cells("E"), soucol_channel = sh1.cells("F")

I tried to do it by this but VBA responds with error我试图这样做,但 VBA 响应错误

Application.screenupdating = False
For i = firstrow to lr
If Sh1.Cells(i, soucol_provider).Value = "EMS" and Sh1.Cells(i, soucol_channel).Value = "by air" Then 

#copy and paste the data in current row to the sheet"ems_by_air' nex i I have no idea if there is much better way to achieve this...would you guys shed some light on this? FIY: It's not just copy and paste the exact data to the sheets since the column order in each sheet is different. #将当前行中的数据复制并粘贴到工作表“ems_by_air” nex 我不知道是否有更好的方法来实现这一点......你们能对此有所了解吗?FIY:这不仅仅是复制和粘贴由于每个工作表中的列顺序不同,因此工作表的确切数据。

As part of your scope, you could select a case for your destination spreadsheet, eg:作为 scope 的一部分,您可以select为您的目标电子表格提供一个案例,例如:

dim destSheet as worksheet
Select case true
    case deliveryProvider = "X" and channel="Y"
        set destSheet = sheets(1)
    case deliveryProvider = "A" and channel="B"
        set destSheet = sheets(2)
End select
With destSheet
    'use .notation
End with

You can set up conditions as you deem fit, to account for your number of factors/variables.您可以设置您认为合适的条件,以说明您的因素/变量的数量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 根据第一张工作表中第二个单元格的值,将数据从一个单元格复制到另一张工作表中的单元格? - Copy data from one cell to a cell in another sheet based on the value of a second cell in the first sheet? 在每个工作表匹配的单元格上复制一个单元格并将其粘贴到另一个VBA - Copy a cell on one sheet and paste it on another VBA based on cell from each sheet matching 根据单元格colorindex从一个工作表的粘贴范围复制范围到另一工作表的另一工作表 - Copy Range From One Sheet Paste Part of Range In another Sheet Based On Cell colorindex 基于自动过滤器将粘贴列从一张工作表复制到另一张工作表 - Copy Paste Columns from one sheet to another sheet based on Autofilter 从一个单元格中查找值,从该单元格附近的单元格中复制值,然后将其粘贴到另一张纸上 - Find value from one cell, copy value from cell near to that cell and paste it to another sheet 基于一个单元格值复制行并引用另一个单元格值并粘贴到新工作表上 - Copy rows based on one cell value and in reference to another cell value and paste on a new sheet 从一张纸复制数据并粘贴到另一张纸的A列的第一个空白单元格中 - Copy data from one sheet and paste into the first blank cell in column A of another sheet 根据条件将单元格数据从一张纸复制到另一张纸 - copy cell data from one sheet to another based on condtion 根据单个单元格值将项目复制/粘贴到另一个工作表上 - Copy/Paste Item onto another sheet based on a single cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM