简体   繁体   English

将数据从一张纸解析到许多其他纸

[英]Parsing data from one sheet to many others

There is one sheet, where all data is listed and there are over 9,000 other sheets that reference to that one and take some of that data. 有一张工作表列出了所有数据,还有超过9,000个其他工作表引用了该数据并获取了其中一些数据。

What I have to do manually now: In every single one of that many, I should write formula in certain cell, that references to our "Data-sheet" and takes certain data. 我现在必须手动执行的操作:在其中的每一个中,我都应该在某些单元格中编写公式,该公式引用我们的“数据表”并获取某些数据。 Cell is exactly the same in all sheets. 单元格在所有工作表中完全相同。 The formula looks like this: 公式如下所示:

=ListOfData!A1  

and for second sheet it looks like: 第二张纸看起来像:

=ListOfData!A2  

...and so forth and so on. ...等等等等。

Can I write those formulas in all of the sheets without hardcoding? 我可以在不进行硬编码的情况下将这些公式写在所有工作表中吗?

If I understand what you're needing, here's a quick macro I did for you: 如果我了解您的需求,这是我为您准备的快速宏:

Sub addFormula()
Dim ws As Worksheet
Dim cel As Range

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> "ListofData" Then
        With ws
            'This places the formula in cell A1 of each sheet. Change as necessary!
            .Cells(1, 1).Formula = "=ListOfData!A" & ws.Index
        End With
    End If
Next ws

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Place that in the Workbook module. 将其放在工作簿模块中。 What it will do is use the Sheet Index to determine the formula (ie the second sheet in the index will have =ListofData!A2 in Cell A1 . 它将使用工作表索引确定公式(即索引中的第二个工作表在单元格A1中将具有=ListofData!A2

To change where your formula goes, edit the .Cells(1,1) to fix that (format is .Cells([Row],[Column]) . 要更改公式的位置,请编辑.Cells(1,1)进行修复(格式为.Cells([Row],[Column])

Since you have over 9000 sheets, I am hoping to all the gods that their indexes are the same number you want. 既然您有9000多张纸,我希望所有的神明他们的索引都是您想要的数字。 If not, you'll need to specify how we know which sheet gets A1 , A2 ,..., A9000 in the formula. 如果不是,则需要指定我们如何知道哪个工作表在公式中获得A1A2 ,..., A9000

I highly suggest trying this in a copy of the workbook, with say 40 sheets before using this on the large one. 强烈建议您在工作簿的副本中尝试使用40张纸,然后再在较大的书本上使用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM