View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JW[_2_] JW[_2_] is offline
external usenet poster
 
Posts: 638
Default How do I find all zip codes from the web?

Here is a quick one to hit getzips.com and bring back the data for
Alamance county NC.
Sub this()
Dim cty As String, state As String
cty = "Alamance"
state = "NC"
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://getzips.com/CGI-BIN/ziplook.exe?What=3&County=" &
_
cty & "&State=" & state & "&Submit=Look+It+Up" _
, Destination:=Range("A1"))
.Name = cty & " " & state
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "3"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

You can just adjust the values assigned to the variables with a value
from a range reference. Example:
state=Range("S2").Text

A simple loop could be added to cycle through all of the records in
your sheet and place the data in the approriate place, instead of just
A1 which is what the above does.

If you need help accomplishing this, let me know. I'll try to get
back on here later this evening and have a closer look at what you are
describing.
IntricateFool wrote:
How would I go about looking through a list of counties and retrieving all of
the countys' respective zip codes through a web site such as:

http://www.getzips.com

So I would have different territories set up in a reference area (e.g cells
A2:S20 contain a list of counties - column A would containTerritory1,
Territory2, Territory3 - Territory19 and columns B through S would contain
each territories respective counties). Below (starting in cell A22) I would
like to list out all zip codes, city and state and county names (all data
that is shown from getzips.com) for each of the counties. The script would
look through each county on the getzips.com website and output all zip codes
for every county listed in the reference area.

So if I wanted to lookup "bucks" county "pennsylvania" I could do so by
following:

http://www.getzips.com/CGI-BIN/ziplo...t=Lo ok+It+Up

What would be the easiest way to go about doing this? I have several
thousand counties that I would need this information for and I know this is
possible with a script... Just not sure how to even begin.

Please help!