I have just worked out how to get data into a table using excel web query. 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?
Asked
Active
Viewed 297 times
1 Answers
0
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.

ArtPur
- 9
- 7