• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to avoid error if value ="" in for loop

Nitesh Khot

Member
Hi,

Attached file contains Chandoos Lat & long program..I want to modified code to do work as for loop but getting error when postal code is not available...I want to check postal code is blank if blank then zip code show"not found."

Error in code is below and Also File attached...

Code:
Zip = Mid(apan, InStr(1, apan, "<type>postal_code</type>") - 21, 6)
 

Attachments

Put the following just before your line Zip =

on error resume next

then change Tet1 as below

Code:
Sub Test1()
'
  Dim Address1 As String
  Dim Lat_Lon1 As String
  Dim Zip1 As String
  Dim i As Range
  Dim lastrow As Integer
  lastrow = Range("A" & Rows.Count).End(xlUp).Row
  For Each i In Range("A2:A" & lastrow)
   
  Address1 = i.Value
   
  Zip1 = ""
   
  Call Lat_Lon_Zip(Address1, Lat_Lon1, Zip1)
   
  i.Offset(0, 1).Value = Lat_Lon1 & "-" & Zip1
  Next i
End Sub
 
Last edited:
Thanks for prompt response...Awesome working what i want.....Thank you so much...

Happy Diwali to Chandoo.org..,to you & your family...
 
Back
Top