【问题标题】:Excel web query append to tableExcel Web 查询附加到表
【发布时间】:2018-03-01 14:14:28
【问题描述】:

我刚刚研究了如何使用 excel 网络查询将数据放入表中。但是,每次刷新数据时,它都会覆盖顶部的最后一次更新。我可以通过在每次刷新时将数据附加到现有表而不是覆盖和丢失旧数据来使用 Web 查询将数据加载到表中吗?如果可以,该怎么做?

【问题讨论】:

    标签: excel-web-query


    【解决方案1】:

    迈克,我建议制作一张包含您最终数据的表格,然后将您的最新数据复制到该表格中。所以你有一个接收新数据的更新表和另一个在旧数据下存储新数据的表

    `'Get onto the right sheet to copy daata
      Sheets("Data").Select
     'Start a loop
      Dim x As Integer
      Application.ScreenUpdating = False
      ' Set numrows = number of rows of data.
      NumRows = Range("A2", Range("A2").End(xlDown)).Rows.Count
      ' Select cell a2.
      Range("A2").Select
      ' Establish "For" loop to loop "numrows" number of times.
      For x = 1 To NumRows
    
        Selection.copy
        'Get onto the right sheet
        Sheets("APIcall").Select
    
        'Activate the query for the specific data
    
        'delete the query so that it can be used again and unlist it to be able to manipulate it 
        ActiveWorkbook.Queries("query").Unlist       
        ActiveWorkbook.Queries("query").Delete
    
        'copy the info into the Data sheet into the next blank row
        Sheets("APIcall").Select
        Range("A2", Range("A2").End(xlToRight)).Select
        Selection.copy
        Sheets("Data").Select
        Range("A" & Rows.Count).End(xlUp).Offset(1).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
        Sheets("APIcall").Cells.Clear
    
    'get the next data
    Sheets("Data").Select
    ActiveCell.Offset(1, 0).Select
    Next`
    

    这很可能可以做得更好、更简单,但希望能有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多