将值从特定单元格复制到摘要表单

时间:2014-01-13 19:50:50

标签: excel-vba copy excel-2010 summary vba

我对VBA很陌生,我已经设法通过使用论坛和一些切割和面食在这里和那里,但似乎我不能再进一步。我有一个工作簿,其中包含100个工作表,标题为1_OUT_IX_-500.TXT,2_OUT_IX_-490.TXT等等,直到101_OUT_500.TXT,我正在尝试从所有工作表上的相同范围复制数据,特别是AO2:AQ2和意大利面B2:D2范围内的新摘要表,因此第一行是bllank,允许我添加标题。所以摘要表看起来像

-500'1_OUT_IX_-500'$ AO $ 2'1_OUT_IX_-500'$ AP $ 2'1_OUT_IX_-500'$ AQ $ 2

-490'2_OUT_IX_-490'$ AO $ 2'2_OUT_IX_-490'$ AP $ 2'2_OUT_IX_-490'$ AQ $ 2


500'101_OUT_IX_500'$ AO $ 2'101_OUT_IX_500'$ AP $ 2'101_OUT_IX_500'$ AQ $ 2

非常感谢任何帮助 提前谢谢

2 个答案:

答案 0 :(得分:1)

试试这段代码:

 Sub test()
    Dim summarySheet As Worksheet
    Dim sh As Worksheet

    Dim j As Integer

    'change "Summary" to the sheet name that is true for you'
    Set summarySheet = ThisWorkbook.Worksheets.Add
    summarySheet.name = "Summary"

    'number of first row where need to paste in summary sheet'
    j = 2
    'loop throught all sheets'
    For Each sh In ThisWorkbook.Worksheets
        If sh.Name <> summarySheet.Name Then
            summarySheet.Range("B" & j & ":D" & j).Value = _
                sh.Range("AO2:AQ2").Value
            j = j + 1
        End If
    Next

End Sub

请注意,您需要在行Set summarySheet = ThisWorkbook.Worksheets("Summary")

中为摘要表指定正确的名称

答案 1 :(得分:0)

您可以在不使用Macro的情况下执行此操作。您只需使用INDIRECT功能。

示例:

+----+------------------+--------------------+-------+---------------------+
| Id |       Plan       |     Plan Name      | Range |        Value        |
+----+------------------+--------------------+-------+---------------------+
|  1 | _OUT_IX_-500.TXT | =A2 & B$2          | !A1   | =INDIRECT(C2 & D$2) |
|  2 |                  | 2_OUT_IX_-500.TXT  |       |                     |
|  3 |                  | 3_OUT_IX_-500.TXT  |       |                     |
|  4 |                  | 4_OUT_IX_-500.TXT  |       |                     |
|  5 |                  | 5_OUT_IX_-500.TXT  |       |                     |
|  6 |                  | 6_OUT_IX_-500.TXT  |       |                     |
|  7 |                  | 7_OUT_IX_-500.TXT  |       |                     |
|  8 |                  | 8_OUT_IX_-500.TXT  |       |                     |
|  9 |                  | 9_OUT_IX_-500.TXT  |       |                     |
| 10 |                  | 10_OUT_IX_-500.TXT |       |                     |
|    |                  |                    |       |                     |
+----+------------------+--------------------+-------+---------------------+

我将此代码放在摘要表中,并将Id表放在单元格A1中。