Dynamic Query

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Re: Dynamic Qurey

Depends what you're trying to accomplish, something like this i'd set up some cells to enter the values I need in, and use that to build the URL I needed for my query.

Something like this

Code:
Sub Macro1()


Dim locstr As String
Dim yearstr As String
Dim daystr As String
Dim monthstr As String


locstr = Sheets("Sheet2").Range("A1").Value
yearstr = Sheets("Sheet2").Range("A2").Value
daystr = Sheets("Sheet2").Range("A3").Value
monthstr = Sheets("Sheet2").Range("A4").Value


With ActiveSheet.QueryTables(1)
    .Connection = "URL;http://www.realtimetrains.co.uk/search/advanced/" & locstr & "/" & yearstr & "/" & daystr & "/" & monthstr & "/0000-2359?stp=WVS&show=all&order=wtt"
    .Refresh
End With


End Sub
 
Upvote 0
Re: Dynamic Qurey

Thanks I will give this ago as it’s what I was looking for to input value in the sheet and return a query from the site.
 
Upvote 0
Re: Dynamic Qurey

I've tried the code but got stuck with A Debug error "With ActiveSheet.QueryTables(1)"
 
Last edited:
Upvote 0
Re: Dynamic Qurey

It will need to be changed to your current query table.

In this case I set up a query table with your current URL, then used that code to change it as the user updates the values.
 
Upvote 0
Re: Dynamic Qurey

Hiya,
I must be something really wrong here to get this working correctly using the code below
and have included in yellow the fields that need to change the URL address before it looks up query and find results.

[TABLE="width: 321"]
<tbody>[TR]
[TD="width: 114, bgcolor: transparent"]Lcoation Name:
[/TD]
[TD="width: 313, bgcolor: transparent"]Sittingbourne Western Junction
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]CRS Code:
[/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]TIPLOC:
[/TD]
[TD="bgcolor: yellow"]STNGWJN
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Stanox No:
[/TD]
[TD="bgcolor: transparent"]89028

[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"][/TD]
[TD="bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="bgcolor: transparent, colspan: 2"]Realtrains
[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Day:
[/TD]
[TD="bgcolor: yellow"]28

[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Month:
[/TD]
[TD="bgcolor: yellow"]09

[/TD]
[/TR]
[TR]
[TD="bgcolor: transparent"]Year:
[/TD]
[TD="bgcolor: yellow"]2018
[/TD]
[/TR]
</tbody>[/TABLE]

It needs to get data from: http://www.realtimetrains.co.uk/sea...18/09/28/0000-2359?stp=WVS&show=all&order=wtt
 
Upvote 0
Re: Dynamic Qurey

Evening,
I must be doing something really wrong with the code as itsnot working for me to change the fields of Location, Date before downloading aQuery from website. I have shared the sheet in Google Drive if somebody canhelp please?

http://www.realtimetrains.co.uk/search/advanced/STNGWJN/2018/09/28/0000-2359?stp=WVS&show=all&order=wtt

Mainsheet highlighted in YELLOW connected with above red

https://drive.google.com/file/d/16ZN55QZtXNPoxBUOGO60rt_F2TbcSKMG/view?usp=sharing
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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