首页 \ 问答 \ 宏从一个工作表中逐列复制和粘贴到主工作表中,以保持增长的数据(Macro to copy and paste column by column from one sheet into master sheet by header to maintain growing data)

宏从一个工作表中逐列复制和粘贴到主工作表中,以保持增长的数据(Macro to copy and paste column by column from one sheet into master sheet by header to maintain growing data)

我是Excel VBA的新手,一直在努力寻找(以及提出我自己的)解决方案,以应对我所面临的困境。 通常,我从同事那里收到原始数据文件,这些原始数据文件可能有不同数量的列,但标题名称一致。 我在我的工作簿中有一个主电子表格,我希望通过附加新数据来保持最新(因此请将新电子表格的数据附加到下一个空行)。 我想创建一个宏,可以获取导入的电子表格(例如,电子表格A)并查看列的标题值,复制列范围(从第2行开始到列填充结束),转到电子表格主页,查找标题值,并将列范围粘贴到列中的下一个空单元格中。 此过程适用于电子表格A中的所有列。

任何帮助/指导/建议将非常感谢。

例)我有“主”表和“进口”表。 我想获取“导入”表格,从第1列开始查看第1行中的标题。如果该标题出现在“主”表格中,请从“导入的表格”中复制该列(减去标题)并粘贴到“掌握“在该列中下一个空单元格开始的相应列标题下。 我最终想要做的是保留“主”表与历史数据,但“导入”表包含移动的列,所以我无法复制和粘贴范围从主下一个空单元格开始。


I am fairly new to Excel VBA and have been trying to look for (as well as come up with my own) solutions to a dilemma I am facing. Routinely, I receive raw data files from a colleague and these raw data files may have varying number of columns but consistent header names. I have in my workbook, a master spreadsheet that I want to keep up to date by appending the new data (so keep appending data of new spreadsheet to next empty row). I would like to create a macro that can take the imported spreadsheet (say, spreadsheet A) and look at the header value of a column, copy the column range (starting from row 2 to end of populated within column), go to spreadsheet Master, look for header value, and paste the column range in the next empty cell down in the column. And this procedure would be for all columns present in spreadsheet A.

Any help/guidance/advice would be very much appreciated.

Ex) I have "master" sheet and "imported" sheet. I want to take the "imported" sheet, look at headers in row 1, starting from column 1. If that header is present in "master" sheet, copy the column (minus the header) from "imported sheet" and paste into "master" under the appropriate column header starting from the next empty cell in that column. What I ultimately want to do is keep the "master" sheet with historical data but the "imported" sheet contains columns which moves around so I just couldn't copy and paste the range starting from next empty cell in master.


原文:https://stackoverflow.com/questions/9802298
更新时间:2021-09-09 16:09

最满意答案

多对多的关系不是你想要的,因为任何设备(我假设)只能有一个制造商。

您确实需要一个存储模型信息的中间模型,而您的EquipmentModel已有一个模型信息。 我建议修改如下:

class EquipmentModel(models.Model):
    # This stores information about a particular model of device
    manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE)
    model_number = models.CharField(max_length=50)

然后,不要在Device为制造商提供外键,而是将其替换为设备型号的外键:

class Device(models.Model):
   # ...
   model = models.ForeignKey('EquipmentModel', on_delete=models.CASCADE)

A many-to-many relationship is not what you want here, because any piece of equipment (I assume) can only have one manufacturer.

You do need an intermediate model which stores the model information, and you already have one in your EquipmentModel. I would suggest modifying it as follows:

class EquipmentModel(models.Model):
    # This stores information about a particular model of device
    manufacturer = models.ForeignKey('Manufacturer', on_delete=models.CASCADE)
    model_number = models.CharField(max_length=50)

And then instead of having a foreign key to the manufacturer in Device, replace it with a foreign key to the equipment model:

class Device(models.Model):
   # ...
   model = models.ForeignKey('EquipmentModel', on_delete=models.CASCADE)

相关问答

更多
  • 如果可能的话,远离单身人士 辛格尔顿有它的用途,但我相信它在很多情况下被滥用。 单身人士最大的问题是你使用的是全局状态,一般认为这是一件坏事,因为当你的软件复杂度增加时,它可能会导致你意想不到的副作用。 对象组合可能是更好的方法 对于游戏,您可能需要查看使用Object Composition而不是传统的OOD Modeling。 软件组件是符合组件模型的软件组件,并且可以根据组合标准独立地部署和组合,而无需修改。 组件模型定义了特定的交互和组合标准。 组件模型实现是支持符合模型的组件执行所需的专用可执行软 ...
  • 我在现在的公司看到了这两种方法,一定会倾向于第一(基于股票交易的总计)。 如果您只将总量存储在某个地方,您就不知道如何到达该号码。 没有交易历史,你可能会遇到问题。 我写的最后一个系统通过将每个交易存储为正数或负数的记录来跟踪股票。 我发现它的效果很好。 I have seen both approaches at my current company and would definitely lean towards the first (calculating totals based on stock ...
  • 你应该使用多对多关系。 首先,您应该从User模型中删除FK。 然后为项目创建单独的模型,最后将许多用户链接到多个项目(一个用户可以处理多个项目,一个项目可以属于多个用户)。 像这样的东西: class User(models.Model): name = models.CharField(max_length=100) class item(models.Model): name =models.CharField(max_length=40) class inventory(mo ...
  • 您可以创建一个抽象基类,并让这两个模型继承它: class InvoiceAbstract(models.Model): invoiceid = models.CharField(max_length=20) totalamount = models.DecimalField(max_digits=15,decimal_places=2,default=0) downpayment = models.DecimalField(max_digits=15,decimal_places= ...
  • 我可以想到一些解决方案 制作数量和MaxQuantity - 然后单数的项目的MaxQuantity为1 制作一个可以从弹药等继承的StackableItem类,然后你可以在其中包含一个数量,如果你愿意的话,它仍然可以让你在不同的空间中携带同一个物品的多个物品。 红色(臂章?)的屏幕截图显示了一个例子 There are a couple solutions that I can think of Make a Quantity and a MaxQuantity - Then items that are ...
  • 你可以使用信号 。 特别是django.db.models.signals.post_save和django.db.models.signals.post_delete 。 对于跟踪历史记录,我建议使用django-reversion 。 You can use signals. In particular django.db.models.signals.post_save and django.db.models.signals.post_delete. For tracking history I r ...
  • 多对多的关系不是你想要的,因为任何设备(我假设)只能有一个制造商。 您确实需要一个存储模型信息的中间模型,而您的EquipmentModel已有一个模型信息。 我建议修改如下: class EquipmentModel(models.Model): # This stores information about a particular model of device manufacturer = models.ForeignKey('Manufacturer', on_delete=mod ...
  • 由于您将在多用户更新环境中工作,因此您需要确保与其他用户没有冲突。 最安全的方法是使用TRANSACTION。 接下来,您需要决定如何以及何时更新两个表。 让我们选择“选项1”,即用户在完成后点击一个按钮。 单击按钮时需要调用以下子例程。 您还应该跟踪用户是否对子窗体进行了任何更改,但忘记单击“保存”按钮。 然后我强烈建议你跟踪你所做的改变。 例如,用户输入数量为5,保存更改。 明天,查看数据,看到5,并希望将其更改为6 ...这将破坏真正的库存。 要防止的一种方法是为PO订单项设置一个“标记”,表明它们已 ...
  • 您可能应该添加另一个表格products ,其中包含当前库存量。 然后,您可以创建products与purchases和sales之间的雄辩关系。 因此, purchases和sales的product_id列指向products表。 有关详细信息,请参阅: https : //laravel.com/docs/5.3/eloquent-relationships 然后,一旦您需要添加新的销售,您就可以进行交易,检查产品的当前库存量是否高于销售的产品数量。 如果一切顺利,您将更新库存中的当前金额并为销售表创 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)