+ Reply to Thread
Results 1 to 6 of 6

Trouble getting IE to stop when there is no data in the column

Hybrid View

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    atlanta ga
    MS-Off Ver
    Excel 2007
    Posts
    36

    Trouble getting IE to stop when there is no data in the column

    So I made this Macro to open up IE and enter in the data for columns a and b, then extract info from the website. The problem I am having is that since I set "a" as an integer, it will just keep going through row 500 or so. What I really need it to do is stop when there are no more addresses. Can someone help me with this? Attached is the spreadsheet with the code in it.

    Thanks!GeoTax Query.xlsm

    Also here is the code

    Sub GeoTax()


    Dim a As Integer


    For a = 1 To 500



    Set ie = CreateObject("internetexplorer.application")
    ie.Visible = False
    ie.Navigate "http://www.geotax.com/USTaxLookup/"

    Do While ie.ReadyState <> 4 Or ie.Busy = True
    DoEvents
    Loop



    If ie.document.Title = "GeoTAX - Free Instant Sales and Use Tax Rates" Then
    ie.document.getelementbyid("tbAddress").Value = Range("Address")(a + 1)
    ie.document.getelementbyid("tbLastline").Value = Range("Zip")(a + 1)
    ie.document.all("tbTaxValue").Value = "100"
    ie.document.getelementbyid("btnGO").Click
    Do While ie.ReadyState <> 4 Or ie.Busy = True

    DoEvents
    Loop

    If Left(ie.document.getelementbyid("__VIEWSTATE").Value, 15) <> "/wEPDwUIOTEyOTE" Then



    Range("Muni")(a + 1).Value = ie.document.getelementbyid("lblmuni").innerText
    Range("County")(a + 1).Value = ie.document.getelementbyid("lblcounty").innerText
    Range("State")(a + 1).Value = ie.document.getelementbyid("lblState").innerText
    Range("County")(a + 1).Value = ie.document.getelementbyid("lblcounty").innerText
    Range("State")(a + 1).Value = ie.document.getelementbyid("lblState").innerText
    Range("SalesTax")(a + 1).Value = ie.document.getelementbyid("lblSalesTax").innerText
    Range("UseTax")(a + 1).Value = ie.document.getelementbyid("lblUseTax").innerText

    End If

    End If


    ' ie.Quit



    Next a



    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Trouble getting IE to stop when there is no data in the column

    either change your for loop to a do until loop or insert an if ... exit for command.

    e.g.
    sub macro_1()
    dim count
    count = 1
    do until Range("A" & count) = ""
      'do code
    loop
    end sub
    or
    sub macro_2()
    dim count
    for count = 1 to 500
      if Range("A" & count) = "" then exit for
      'do code
    end if

  3. #3
    Registered User
    Join Date
    01-04-2013
    Location
    atlanta ga
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Trouble getting IE to stop when there is no data in the column

    Sorry, I am just learning VBA. Would you mind giving me the complete code of the two options you provided?


    Thanks!!

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Trouble getting IE to stop when there is no data in the column

    Sub GeoTax()
    Dim a As Integer
    For a = 1 To 500
        If Range("Address")(a + 1) = "" Then Exit For
        Set ie = CreateObject("internetexplorer.application")
        ie.Visible = False
        ie.Navigate "http://www.geotax.com/USTaxLookup/"
        Do While ie.ReadyState <> 4 Or ie.Busy = True
            DoEvents
        Loop
        If ie.document.Title = "GeoTAX - Free Instant Sales and Use Tax Rates" Then
            ie.document.getelementbyid("tbAddress").Value = Range("Address")(a + 1)
            ie.document.getelementbyid("tbLastline").Value = Range("Zip")(a + 1)
            ie.document.all("tbTaxValue").Value = "100"
            ie.document.getelementbyid("btnGO").Click
            Do While ie.ReadyState <> 4 Or ie.Busy = True
                DoEvents
            Loop
            If Left(ie.document.getelementbyid("__VIEWSTATE").Value, 15) <> "/wEPDwUIOTEyOTE" Then
                Range("Muni")(a + 1).Value = ie.document.getelementbyid("lblmuni").innerText
                Range("County")(a + 1).Value = ie.document.getelementbyid("lblcounty").innerText
                Range("State")(a + 1).Value = ie.document.getelementbyid("lblState").innerText
                Range("County")(a + 1).Value = ie.document.getelementbyid("lblcounty").innerText
                Range("State")(a + 1).Value = ie.document.getelementbyid("lblState").innerText
                Range("SalesTax")(a + 1).Value = ie.document.getelementbyid("lblSalesTax").innerText
                Range("UseTax")(a + 1).Value = ie.document.getelementbyid("lblUseTax").innerText
            End If
        End If
        ' ie.Quit
    Next a
    End Sub

  5. #5
    Registered User
    Join Date
    01-04-2013
    Location
    atlanta ga
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Trouble getting IE to stop when there is no data in the column

    Thanks so much!!!

  6. #6
    Registered User
    Join Date
    01-04-2013
    Location
    atlanta ga
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Trouble getting IE to stop when there is no data in the column

    Anyway you could update the macro you made for me a long time ago for the new website. I have no idea why it isn't working. Here is the new website

    http://taxco.g1.com/

+ 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. How To Get Excel To Stop Auto-Formatting my Column Data Types
    By kmccrack@gmail.com in forum Excel General
    Replies: 5
    Last Post: 03-15-2006, 08:10 AM
  2. How do you Stop Entering Duplicate Data in a Column?
    By Satraj in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-04-2005, 09:10 AM
  3. [SOLVED] How can i stop same data being repeated in a column
    By Ru in forum Excel General
    Replies: 3
    Last Post: 05-23-2005, 04:06 PM
  4. [SOLVED] How can i stop data being repeated within a column?
    By Ru in forum Excel General
    Replies: 2
    Last Post: 05-23-2005, 12:06 PM
  5. Replies: 0
    Last Post: 05-17-2005, 05:49 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