PDA

View Full Version : Solved: Importing space delimited text files



Carl A
08-18-2008, 01:07 PM
I have text files with the zip codes of various cities. These files are delimited with spaces.

I use johnske text import from the KB
http://vbaexpress.com/kb/getarticle.php?kb_id=497

examples:
Zip City Area Code

62820 Burnt Prairie 618
60527 Burr Ridge 630

60102 Lake in the Hills 847

The cities with two names I can join together with
=IF(ISTEXT(Import!C:C),Import!B:B&" "&Import!C:C,Import!B:B)

But I'm having trouble with cities with 3 names or more.

A better formula would be appreciated or better a VBA routine that can automate the process.

I have included sample text file in the zip.

Any assistance will be appreciated TIA!

Mavyak
08-18-2008, 01:33 PM
Sub format_zip_city_area_code_data()
Dim c As Range
Dim x As Integer
Dim zip As String, city As String, ac As String

For Each c In ActiveSheet.Range("A1:A" & ActiveSheet.Range("A65536").End(xlUp).Row)
myCount = c.End(xlToRight).Column - 1
For x = 0 To myCount
Select Case x
Case Is = 0
zip = c.Offset(0, x).Value
Case Is = myCount
ac = c.Offset(0, x).Value
Case Else
city = city & " " & c.Offset(0, x).Value
End Select
Next x
c.EntireRow.Clear
c.Value = zip: zip = ""
c.Next = Trim(city): city = ""
c.Next.Next = ac: ac = ""
Next c

Set c = Nothing
End Sub

Probably an easier way to do this but in a picnh, the above code works.

Mavyak
08-18-2008, 01:36 PM
Note: Be careful copying/pasting zip codes in Excel. It has a tendency to lop off leading zeroes resulting in the nort-eastern values being only 4 digits long.

Cleaner007
08-18-2008, 01:41 PM
Does anybody know about Clone Remover? It's said to be a good duplicate file removal tool. These guys here - moleskinsoft.com

Carl A
08-18-2008, 01:46 PM
Note: Be careful copying/pasting zip codes in Excel. It has a tendency to lop off leading zeroes resulting in the nort-eastern values being only 4 digits long.
Thanks for the code works really nice.:thumb

For the time being I don't have to worry about east coast zips but eventually I will.

Carl A
08-18-2008, 09:39 PM
Does anybody know about Clone Remover? It's said to be a good duplicate file removal tool. These guys here - moleskinsoft.com

This has been reported as spam on other sites. Even uses same name.

Mavyak
08-19-2008, 07:38 AM
This has been reported as spam on other sites. Even uses same name.
It's spam here too:

http://vbaexpress.com/forum/search.php?searchid=294315