简体   繁体   中英

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.

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 .

To change where your formula goes, edit the .Cells(1,1) to fix that (format is .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. If not, you'll need to specify how we know which sheet gets A1 , A2 ,..., A9000 in the formula.

I highly suggest trying this in a copy of the workbook, with say 40 sheets before using this on the large one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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