简体   繁体   English

Excel Web查询追加到表

[英]Excel web query append to table

I have just worked out how to get data into a table using excel web query. 我刚刚想出了如何使用Excel Web查询将数据获取到表中。 However, every time the data is refreshed it overwrites the last update over the top. 但是,每次刷新数据时,都会覆盖顶部的最新更新。 Can I use web query to load data into a table by appending to the existing table on each refresh instead of overwriting and losing the older data and if so how? 我可以使用Web查询通过在每次刷新时将数据附加到现有表中而不是覆盖和丢失较旧的数据来将数据加载到表中吗?

Mike, I suggest making a sheet with your final data in it and copy your latest data into that sheet. 迈克,我建议制作一张包含最终数据的表,然后将最新数据复制到该表中。 So you have an update sheet that receives the new data and another sheet that stores the new data under the old data 因此,您有一个更新工作表来接收新数据,另一个工作表是将新数据存储在旧数据下

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

This can most probably be done better and simpler, but hope it helps a bit. 这很可能可以做得更好,更简单,但希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM