Validate Address via USPS

mdo8105

Board Regular
Joined
Nov 13, 2015
Messages
83
Hi,

I have a sheet that has the street address information Columns 2-5. The rows are dynamic. I am attempting to take the data on Sheet Address Verification and have it connect to USPS site and pull back the correct USPS format on the same sheet; however, I am getting an Object error 91. Here is my code
Code:
Sub USPS()Dim eRow As Long
Dim ele As Object
Dim lrow As Integer
'Dim IE As New InternetExplorer
Sheets("Address Verification").Select


eRow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Set objie = CreateObject("InternetExplorer.Application")




lrow = ThisWorkbook.Worksheets("Address Verification").Cells(Rows.Count, 2).End(xlUp).Row


For r = 5 To lrow


myaddress = Cells(r, 2).Value
mycity = Cells(r, 3).Value
mystate = Cells(r, 4).Value
myzipcode = Cells(r, 5).Value


'myaddress = Range("a2").Value
'mycity = Range("c2").Value
'mystate = Range("d2").Value
'myzipcode = Range("e2").Value




With objie
.Visible = True
.navigate "https://tools.usps.com/go/ZipLookupAction!input.action"
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
Set what = .document.getElementsByName("tAddress")
what.Item(0).Value = myaddress
Set ZipCode = .document.getElementsByName("tCity")
ZipCode.Item(0).Value = mycity
Set zipcode1 = .document.getElementsByName("sState")
zipcode1.Item(0).Value = mystate
Set zipcode2 = .document.getElementsByName("Zzip")
zipcode2.Item(0).Value = myzipcode


.document.getElementById("lookupZipFindBtn").Click


Do While .Busy Or _
.readyState <> 4
DoEvents
Loop




For Each ele In .document.all
Select Case ele.className


Case "address1 range"
Worksheets("Address Verification").Cells(r, 7).Value = ele.innerText


Case "city range"
Worksheets("Address Verification").Cells(r, 8).Value = ele.innerText


Case "state range"
Worksheets("Address Verification").Cells(r, 9).Value = ele.innerText


Case "zip"
Worksheets("Address Verification").Cells(r, 10).Value = ele.innerText


Case "zip4"
Worksheets("Address Verification").Cells(r, 10).Value = ele.innerText


End Select
'
Next ele
End With


Next r
Set objie = Nothing
Set ele = Nothing
Set IE = Nothing
    
'IE.Quit




End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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