Dynamic web query question

gareths

New Member
Joined
Aug 5, 2011
Messages
7
I am currently using a web query to find the postcodes from an external site:

Code:
Private Sub commandbutton1_click()
    www = "URL;http://api1.nearby.org.uk/api/convert.php?key=431b753ede6408&p=" _
    & Range("U2") & "&want=postcode-uk&output=text"
    With ActiveSheet.QueryTables.Add(Connection:=www, Destination:=Range("W2"))
 
        .Name = "convert.php?key=431b753ede6408&p=""""&want=postcode-uk&output=text"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = False
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlSpecifiedTables
        .WebFormatting = xlWebFormattingNone
        .WebTables = """postcodes"""
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
End Sub

I'm just wondering if I'm able to change W2 so it is the active cell and U2 so it is the active cell - 2.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What do you mean by 'active cell - 2'? 2 rows before, 2 columns before, its value -2, etc.?

Something like this may help. Use negative Offset arguments to get 2 rows/columns before. I've assumed you mean 2 rows before.
Code:
    www = "URL;http://api1.nearby.org.uk/api/convert.php?key=431b753ede6408&p=" _
    & ActiveCell.Offset(-2, 0) & "&want=postcode-uk&output=text"
    With ActiveSheet.QueryTables.Add(Connection:=www, Destination:=ActiveCell)
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,912
Members
452,949
Latest member
beartooth91

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