Excel Web查询附加到表

时间:2018-03-01 14:14:28

标签: excel-web-query

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

1 个答案:

答案 0 :(得分:0)

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

`'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`

这最有可能做得更好更简单,但希望它有所帮助。