Changing data in the web address of a web query by input

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You can use the HYPERLINK function like this:

=HYPERLINK("http://www.xxxxxxxx.com/Example/cgihistory.cgi?id="&A1&"&begin=2001&end=2008")
 
Upvote 0
sorry Andrew, the address is in the Edit Query which i made to get data from the webpage, it is not possible to enter that in the address field, possible to use a VBA code to do this?
 
Upvote 0
Like this?

ActiveSheet.QueryTables(1).Connection = "URL;http://www.xxxxxxxx.com/Example/cgihistory.cgi?id=" & Range("A1").Value & "&begin=2001&end=2008"
 
Upvote 0
how does it work? can you make a complete code?

Let me describe again what I am doing,

in cell B2, select Data > Get External Data > New Web Query > Enter the address in the web address field (http://www.xxxxxxxx.com/Example/cgihistory.cgi?id=1111&begin=2001&end=2008)

but I will have to edit the query everytime when I am searching a new data (2222 etc), I am thinking of by just entering the 4 digit value (2222) in cell A1, the address in Web Query will change by itself and search the web for the data,

possible?
 
Upvote 0
ianccy

To get code why not record a macro (Tools>Macro>Record New Macro) when you do the Data> etc manually?
 
Upvote 0
I just recorded this.

Code:
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;http://www.xxxxxxxx.com/Example/cgihistory.cgi?id=1111&begin=2001&end=2008" _
        , Destination:=Range("B2"))
        .Name = "cgihistory.cgi?id=1111&begin=2001&end=2008"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With
 
Upvote 0
ianccy said:
how does it work? can you make a complete code?

Let me describe again what I am doing,

in cell B2, select Data > Get External Data > New Web Query > Enter the address in the web address field (http://www.xxxxxxxx.com/Example/cgihistory.cgi?id=1111&begin=2001&end=2008)

but I will have to edit the query everytime when I am searching a new data (2222 etc), I am thinking of by just entering the 4 digit value (2222) in cell A1, the address in Web Query will change by itself and search the web for the data,

possible?

Right click the sheet tab and choose View Code. Paste this into the window on the right:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.Address <> "$A$1" Then Exit Sub
   With ActiveSheet.QueryTables(1)
      .Connection = "URL;http://www.xxxxxxxx.com/Example/cgihistory.cgi?id=" & Range("A1").Value & "&begin=2001&end=2008"
      .Refresh
   End With
End Sub

Press Alt+F11 to return to your worksheet. When you change the number in A1 your Query Table Connection will change and the query will be refreshed.
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,454
Members
448,898
Latest member
drewmorgan128

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