根据字符串从不同的工作表获取行

问题描述 投票:0回答:2

我有多张纸,以跟踪每个人的抽奖券数量。

主表:

|-----------|------------------|
|    Name   |     # of tickets |
|-----------|------------------|
|   Adam    |         5        |
|-----------|------------------|
|   Michael |         2        |
|-----------|------------------|
|   Sara    |         4        |
|-----------|------------------|

工作表1:

|-----------|------------------|---------------|
|    Name   |     Activity     | # of tickets  |
|-----------|------------------|---------------|
|   Adam    |  Registration    |        2      |
|-----------|------------------|---------------|
|   Michael |  Registration    |        2      |
|-----------|------------------|---------------|
|   Sara    |  Registration    |        2      |
|-----------|------------------|---------------|

表格2:

|-----------|------------------|---------------|
|    Name   |     Activity     | # of tickets  |
|-----------|------------------|---------------|
|   Adam    |  Registration    |        2      |
|-----------|------------------|---------------|
|   Sara    |  Registration    |        2      |
|-----------|------------------|---------------|
|   Adam    |  Extra ticket    |        1      |
|-----------|------------------|---------------|

问题:我该如何做才能根据工作表1,工作表2 ...工作表n自动更新主工作表?因此,基本上,主要工作表应基于“名称”列获取每个工作表的行,然后获取票证#的值并将其汇总到主要工作表中。

google-sheets google-sheets-formula google-sheets-api google-sheets-query
2个回答
1
投票

像这样回复您的数据:主数据表和2个数据表:

enter image description here

在我的MainSheet中,B1中使用的公式是:

=SUMIF(Sheet1!$A$1:$A$3;A1;Sheet1!$C$1:$C$3)+SUMIF(Sheet2!$A$1:$A$3;A1;Sheet2!$C$1:$C$3)

您要添加的每个工作表都需要一个SUMIF。

Function SUMIF


0
投票

创建代码块宏vba

Sub GetInfoSheet()

    Dim WS_Count As Integer
    Dim I As Integer                             
    Dim SumAdam As Integer
    Dim SumMichel As Integer
    Dim SumSara As Integer

    WS_Count = ActiveWorkbook.Worksheets.Count

    For I = 2 To WS_Count
        strTest = ActiveWorkbook.Worksheets(I).Cells(3, 3)
        SumAdam = SumAdam + CInt(strTest)
        strTest = ActiveWorkbook.Worksheets(I).Cells(4, 3)
        SumMichel = SumMichel + CInt(strTest)
        strTest = ActiveWorkbook.Worksheets(I).Cells(5, 3)
        SumSara = SumSara + CInt(strTest)

    Next I

    With ActiveWorkbook.Worksheets(1)
        .Cells(3, 3).Value = SumAdam
        .Cells(4, 3).Value = SumMichel
        .Cells(5, 3).Value = SumSara

    End With
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.