+ Reply to Thread
Results 1 to 13 of 13

Zillow API VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    04-17-2017
    Location
    Chicago
    MS-Off Ver
    1609
    Posts
    4

    Zillow API VBA

    Hello Excel World,

    I downloaded a VBA code off the internet to get me zillow.com information (real estate website that gives rent estimates and property estimates among other details). All that you do is plug in the address and information is spit out. It works very well with one exception when it gets stuck. A problem occurs when it tries to pulls a rent amount (called rent Zestimate) or a property value (called Zestimate) that is "UNAVAILABLE", then run-time error 91 pops up. My goal is to allow the code to keep running and/or simply skip over that address and it's details and continue down the list.

    Below is the code, I tried to make it in a cool little box so it doesn't take up so much space but gave up.

    Thank you,
    CrazyDg99

    Sub ZillowXML()
    ' Miscrosoft XML v6.0 must be enabled from the VBA editor
    ' To enable, go to Tools>References and check the box next to "Miscrosoft XML v6.0"
    
    ' Zillow API overview and signup
    ' http://www.zillow.com/howto/api/APIOverview.htm
    
    ' Zillow Web Service ID
    ZWSID = "X1-ZWz199mpm4y77v_3e7gq"
    
    ' Number of header columns
    Headers = 2
    
    ' Columns containing addresses
    Address = "A"
    City = "B"
    State = "C"
    Zip = "D"
    
    ' Columns to return data
    ErrorMessage = "E"
    HomeDetails = "F"
    Graphsanddata = "G"
    Mapthishome = "H"
    Comparables = "I"
    latitude = "J"
    longitude = "K"
    ZAmount = "L"
    LastUpdate = "M"
    zLow = "N"
    zHigh = "O"
    Rent = "P"
    RentLastUpdate = "Q"
    RentLow = "R"
    RentHigh = "S"
    Region = "T"
    Overview = "U"
    FSBO = "V"
    forsale = "W"
    
    
    ' DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE GETTING INTO
    '_______________________________________________________________________________
    
    ' Changes to make
    ' Automatically read address from a MsgBox dialog and transpose that list to a new sheet
    ' Automatically create new columns to put data in
    ' Convert new data range to a table and name it "Zillow"
    
    Dim xmldoc As MSXML2.DOMDocument60
    Dim xmlNodeList As MSXML2.IXMLDOMNodeList
    Dim myNode As MSXML2.IXMLDOMNode
    Dim WS As Worksheet: Set WS = ActiveSheet
    
    ' Seth column to display API URL for troubleshooting
    'xmlURL = "E"
    
    ' Tell user the code is running
    Application.StatusBar = "Starting search"
    
    ' Count Rows
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    '___________________________________________________
    
    ' Begin looping through rows to find and insert data
        ' i = 3 leaves the first two row as column headers
        For i = Headers + 1 To LastRow
        
            'Clear previous data from cells
            WS.Range(ErrorMessage & i) = ""
            WS.Range(HomeDetails & i) = ""
            WS.Range(Graphsanddata & i) = ""
            WS.Range(Mapthishome & i) = ""
            WS.Range(Comparables & i) = ""
            WS.Range(latitude & i) = ""
            WS.Range(longitude & i) = ""
            WS.Range(ZAmount & i) = ""
            WS.Range(LastUpdate & i) = ""
            WS.Range(zLow & i) = ""
            WS.Range(zHigh & i) = ""
            WS.Range(Rent & i) = ""
            WS.Range(RentLastUpdate & i) = ""
            WS.Range(RentLow & i) = ""
            WS.Range(RentHigh & i) = ""
            WS.Range(Region & i) = ""
            WS.Range(Overview & i) = ""
            WS.Range(FSBO & i) = ""
            WS.Range(forsale & i) = ""
    
            
            ' Create Zillow API URL
            rowAddress = WS.Range(Replace(Address, " ", "+") & i)
            rowCity = WS.Range(City & i)
            rowState = WS.Range(State & i)
            rowZip = WS.Range(Zip & i)
            ' Comment out to use testing URL
            URL = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=" & ZWSID & "&address=" & rowAddress & "&citystatezip=" & rowCity & "%2C+" & rowState & "%2C+" & rowZip & "&rentzestimate=true"
            ' Local URL for testing
            'URL = ("C:\Users\John\Dropbox\Excel\ZillowXML.xml")
            
            ' Uncomment to Display API URL for troubleshooting
            'WS.Range(xmlURL & i) = ""
            'WS.Range(xmlURL & i).Formula = "=HYPERLINK(""" & URL & """,""API URL"")"
                       
             ' Tell user what address is being searched for
             Application.StatusBar = "Retrieving: " & i & " of " & LastRow - Headers & ": " & rowAddress & ", " & rowCity & ", " & rowState
            
            'Open XML page
            Set xmldoc = New MSXML2.DOMDocument60
            xmldoc.async = False
            
            ' Check XML document is loaded
            If xmldoc.Load(URL) Then
            
                
                Set xmlMessage = xmldoc.SelectSingleNode("//message/text")
                Set xmlMessageCode = xmldoc.SelectSingleNode("//message/code")
                
                ' Check for an error message
                If xmlMessageCode.Text <> 0 Then
                
                    ' Return error message
                    WS.Range(ErrorMessage & i) = xmlMessage.Text
                    
                Else
                    ' Get XML data from Zillow
                    Set xmlHomeDetails = xmldoc.SelectSingleNode("//response/results/result/links/homedetails")
                    Set xmlGraphsAndData = xmldoc.SelectSingleNode("//response/results/result/links/graphsanddata")
                    Set xmlComparables = xmldoc.SelectSingleNode("//response/results/result/links/comparables")
                    Set xmlMapthishome = xmldoc.SelectSingleNode("//response/results/result/links/mapthishome")
                    ' Push data to preadsheet
                    If xmlHomeDetails Is Nothing Then
                        WS.Range(HomeDetails & i) = "No home details available"
                    Else
                        WS.Range(HomeDetails & i).Formula = "=HYPERLINK(""" & xmlHomeDetails.Text & """,""Zillow Details"")"
                    End If
                    If xmlGraphsAndData Is Nothing Then
                        WS.Range(Graphsanddata & i) = "No graphs available"
                    Else
                        WS.Range(Graphsanddata & i).Formula = "=HYPERLINK(""" & xmlGraphsAndData.Text & """,""Graphs & Data"")"
                    End If
                    If xmlComparables Is Nothing Then
                        WS.Range(Comparables & i) = "No comparables available"
                    Else
                        WS.Range(Comparables & i).Formula = "=HYPERLINK(""" & xmlComparables.Text & """,""Zillow Comparables"")"
                    End If
                    If xmlMapthishome Is Nothing Then
                        WS.Range(Mapthishome & i) = "No map available"
                    Else
                        WS.Range(Mapthishome & i).Formula = "=HYPERLINK(""" & xmlMapthishome.Text & """,""Zillow Map"")"
                    End If
                       
                    ' Retrieve Lat & Long
                    Set xmlLatitude = xmldoc.SelectSingleNode("//response/results/result/address/latitude")
                    Set xmlLongitude = xmldoc.SelectSingleNode("//response/results/result/address/longitude")
                    ' Push data to preadsheet
                    WS.Range(latitude & i) = xmlLatitude.Text
                    WS.Range(longitude & i) = xmlLongitude.Text
                    
                    
                    ' Retrieve Zestimate
                    Set xmlZAmount = xmldoc.SelectSingleNode("//response/results/result/zestimate/amount")
                    Set xmlZLastUpdate = xmldoc.SelectSingleNode("//response/results/result/zestimate/last-updated")
                    Set xmlZValLow = xmldoc.SelectSingleNode("//response/results/result/zestimate/valuationRange/low")
                    Set xmlZValHigh = xmldoc.SelectSingleNode("//response/results/result/zestimate/valuationRange/high")
                    ' Push data to preadsheet
                    WS.Range(ZAmount & i) = xmlZAmount.Text
                    WS.Range(ZAmount & i).NumberFormat = "$#,##0_);($#,##0)"
                    WS.Range(LastUpdate & i) = xmlZLastUpdate.Text
                    WS.Range(zLow & i) = xmlZValLow.Text
                    WS.Range(zLow & i).NumberFormat = "$#,##0_);($#,##0)"
                    WS.Range(zHigh & i) = xmlZValHigh.Text
                    WS.Range(zHigh & i).NumberFormat = "$#,##0_);($#,##0)"
                    
                    ' Retrieve RentZestimate
                    Set xmlRZAmount = xmldoc.SelectSingleNode("//response/results/result/rentzestimate/amount")
                    Set xmlRZLastUpdate = xmldoc.SelectSingleNode("//response/results/result/rentzestimate/last-updated")
                    Set xmlRZValLow = xmldoc.SelectSingleNode("//response/results/result/rentzestimate/valuationRange/low")
                    Set xmlRZValHigh = xmldoc.SelectSingleNode("//response/results/result/rentzestimate/valuationRange/high")
                    ' Push data to preadsheet
                    WS.Range(Rent & i) = xmlRZAmount.Text
                    WS.Range(Rent & i).NumberFormat = "$#,##0_);($#,##0)"
                    WS.Range(RentLastUpdate & i) = xmlRZLastUpdate.Text
                    WS.Range(RentLow & i) = xmlRZValLow.Text
                    WS.Range(RentLow & i).NumberFormat = "$#,##0_);($#,##0)"
                    WS.Range(RentHigh & i) = xmlRZValHigh.Text
                    WS.Range(RentHigh & i).NumberFormat = "$#,##0_);($#,##0)"
    
                    ' Retrieve LocalRealEstate
                    Set xmlRegion = xmldoc.SelectSingleNode("//response/results/result/localRealEstate/region")
                    Set xmlOverview = xmldoc.SelectSingleNode("//response/results/result/localRealEstate/region/links/overview")
                    Set xmlFSBO = xmldoc.SelectSingleNode("//response/results/result/localRealEstate/region/links/forSaleByOwner")
                    Set xmlForSale = xmldoc.SelectSingleNode("//response/results/result/localRealEstate/region/links/forSale")
                    ' Push data to preadsheet
                    If xmlRegion Is Nothing Then
                        WS.Range(Region & i) = "No region information available"
                    Else
                        WS.Range(Region & i).Formula = "=HYPERLINK(""" & xmlRegion.Text & """,""Regional Details"")"
                    End If
                    If xmlOverview Is Nothing Then
                        WS.Range(Overview & i) = "No region overview available"
                    Else
                        WS.Range(Overview & i).Formula = "=HYPERLINK(""" & xmlOverview.Text & """,""Region Overview"")"
                    End If
                    If xmlFSBO Is Nothing Then
                        WS.Range(FSBO & i) = "No FSBO available"
                    Else
                        WS.Range(FSBO & i).Formula = "=HYPERLINK(""" & xmlFSBO.Text & """,""For Sale By Owner"")"
                    End If
                    If xmlForSale Is Nothing Then
                        WS.Range(forsale & i) = "No local For Sale Information"
                    Else
                        WS.Range(forsale & i).Formula = "=HYPERLINK(""" & xmlForSale.Text & """,""Active For Sale"")"
                    End If
                    
                    
                End If
                
           ' Document failed to load statement
           Else
           WS.Range(ErrorMessage & i) = "The document failed to load. Check your internet connection."
           
           End If
        
        ' Loop to top for next row
        Next i
        
    ' Tell user the search is complete
    Application.StatusBar = "Search complete!"
    
    End Sub
    Last edited by alansidman; 04-17-2017 at 03:46 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,919

    Re: Zillow API VBA

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    04-17-2017
    Location
    Chicago
    MS-Off Ver
    1609
    Posts
    4

    Re: Zillow API VBA

    Thank you alansidman

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Zillow API VBA

    You need to set a nothing range for all nodes which are empty.
    If you look at one of your line of code.

    Set xmlHomeDetails = xmldoc.SelectSingleNode("//response/results/result/links/homedetails")
     If xmlHomeDetails Is Nothing Then
                        WS.Range(HomeDetails & i) = "No home details available"
                    Else
                        WS.Range(HomeDetails & i).Formula = "=HYPERLINK(""" & xmlHomeDetails.Text & """,""Zillow Details"")"
                    End If
    if the info is empty, it does not error.
    You also need to add to other parts of the code in which there is no data.
    For instance:
     Set xmlZAmount = xmldoc.SelectSingleNode("//response/results/result/zestimate/amount")
    should be
      If xmlZAmount Is Nothing Then
                        WS.Range(ZAmount & i) = "No Amount available"
                        
                      Else
                        WS.Range(ZAmount & i) = xmlZAmount.Text
                      End If
    Last edited by AB33; 04-18-2017 at 05:05 AM.

  5. #5
    Registered User
    Join Date
    04-17-2017
    Location
    Chicago
    MS-Off Ver
    1609
    Posts
    4

    Re: Zillow API VBA

    Thank you AB33! Now next step is to change the "is nothing then" function to "it [specific string] then" I'm going to give this a shot.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Zillow API VBA

    Do you mean

    If Not xmlZAmount Is Nothing Then
    ?

  7. #7
    Registered User
    Join Date
    04-17-2017
    Location
    Chicago
    MS-Off Ver
    1609
    Posts
    4

    Re: Zillow API VBA

    So for instance when you look up the property "15316 Chicago Road, Dolton, IL" on Zillow.com you can see when you go down to Zestimate Details, the Rent Zestiamte is "Unavailable" instead of showing a number. So I have a feeling that it is technically not "nothing" and instead I am trying to find a what to : If xmlZAmount Is "Unavailable" Then (in order to get a string recognized instead of nothing).

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Zillow API VBA

    If Not xmlZAmount Is Nothing Then means two negative is equal to positive.
    If you use set, you have either a value (If Not xmlZAmount Is Nothing) or not (If xmlHomeDetails Is Nothing Then).

  9. #9
    Registered User
    Join Date
    01-23-2019
    Location
    New york, NY
    MS-Off Ver
    2016
    Posts
    1

    Re: Zillow API VBA

    Did you ever fix this completely? Also, would you consider sharing the finished file?

  10. #10
    Registered User
    Join Date
    03-05-2019
    Location
    Denver, Colorado
    MS-Off Ver
    2015
    Posts
    4

    Re: Zillow API VBA

    CrazyDg - do you know how to break out the property details into additional columns instead of including the link? I'm trying to identify the year property's were built without clicking the link. Any help would be appreciated

  11. #11
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,052

    Re: Zillow API VBA

    Quote Originally Posted by pcollins23 View Post
    CrazyDg - do you know how to break out the property details into additional columns instead of including the link? I'm trying to identify the year property's were built without clicking the link. Any help would be appreciated
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original. Please start a new thread - See Forum rule #4

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  12. #12
    Registered User
    Join Date
    12-14-2019
    Location
    NY, USA
    MS-Off Ver
    2019
    Posts
    1

    Re: Zillow API VBA

    Any update on the finished file?

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,052

    Re: Zillow API VBA

    This thread is over 2 years old, kr007, so if the update isnt here now, it probably wont be updated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA to Query Zillow Website
    By dash11 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-11-2019, 12:53 AM
  2. Importing Info from Zillow (and others) through an API
    By timandlindsay in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2016, 01:55 PM
  3. [SOLVED] Zillow xml API extraction
    By sdgenxr in forum Excel Programming / VBA / Macros
    Replies: 45
    Last Post: 06-30-2016, 07:22 PM
  4. Pull Zillow Zestimate Data
    By minggee109 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-02-2016, 01:49 PM
  5. Is there an Excel with Macro sheet for Zillow
    By alopez7 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 07-02-2015, 06:22 AM
  6. VBA Code to Pull Zillow Comps
    By urbscaburb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2014, 01:35 AM
  7. VBA for Webscraping Zillow
    By use_excel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-14-2014, 12:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1