How to bring in new data from web query while preserving the old

tommypkoch

New Member
Joined
Sep 30, 2011
Messages
5
I am trying to bring in data from the web (works) and as is, Excel overwrites the old data with the new. How can I set it up such the Excel brings in the new data and does not overwrite the old?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I think you need VBA to change the destination cell, like this:
Code:
Sub Macro1()

    Dim destCell As Range
    
    With ActiveSheet
        If .QueryTables.Count = 0 Then
            Set destCell = .Range("A1")
        Else
            Set destCell = .QueryTables(1).ResultRange.Offset(0, 1)     'Either next empty column to the right
            'Set destCell = .QueryTables(1).ResultRange.Offset(1, 0)     'Or next empty row below
            .QueryTables(1).Delete
        End If
        
        With .QueryTables.Add(Connection:="URL;http://www.mrexcel.com/forum/excel-questions", Destination:=destCell)
            .Name = "excel-questions"
            .RefreshStyle = xlInsertDeleteCells
            .AdjustColumnWidth = False
            .WebSelectionType = xlEntirePage
            .WebFormatting = xlWebFormattingNone
            .Refresh False
        End With
    End With
    
End Sub
 
Upvote 0
John - I wondered about VBA but was not sure - will give it a try and let you know if I am successful - am booked today so it will be tomorrow before I will get a chance. I apprecaite your help! Tom


I think you need VBA to change the destination cell, like this:
Code:
Sub Macro1()

    Dim destCell As Range
    
    With ActiveSheet
        If .QueryTables.Count = 0 Then
            Set destCell = .Range("A1")
        Else
            Set destCell = .QueryTables(1).ResultRange.Offset(0, 1)     'Either next empty column to the right
            'Set destCell = .QueryTables(1).ResultRange.Offset(1, 0)     'Or next empty row below
            .QueryTables(1).Delete
        End If
        
        With .QueryTables.Add(Connection:="URL;http://www.mrexcel.com/forum/excel-questions", Destination:=destCell)
            .Name = "excel-questions"
            .RefreshStyle = xlInsertDeleteCells
            .AdjustColumnWidth = False
            .WebSelectionType = xlEntirePage
            .WebFormatting = xlWebFormattingNone
            .Refresh False
        End With
    End With
    
End Sub
 
Upvote 0
Hmm,... the VBA code does not seem to do tha trick and there has been a twist in the request. Instead of preserving all the data, is there a way to have the program keep the last trading days' data (CBOT, CME)? I cannot find the data on the web like the futures trading data (current connections).
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,375
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top