0

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

4

1 回答 1

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`

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

于 2018-04-01T13:03:40.577 回答