Blank
New Member
- Joined
- Jun 19, 2009
- Messages
- 14
Hi everyone,
I'm stuck trying to import only the first 3 characters from a .csv file. Right now the code does import that certain column like in the picture below but in fact i want to import only the first 3 characters from those postal codes. After importing, i would like to know how many times is repeating, showing me that in the next column, and finally, in the third column to paste all postal codes without duplicates.
This is the code i am using it right now:
I'll be very greatful to anyone who can help me with this since my boss needs it ASAP :/
Regards,
Alex
I'm stuck trying to import only the first 3 characters from a .csv file. Right now the code does import that certain column like in the picture below but in fact i want to import only the first 3 characters from those postal codes. After importing, i would like to know how many times is repeating, showing me that in the next column, and finally, in the third column to paste all postal codes without duplicates.
This is the code i am using it right now:
VBA Code:
Sub ImportCSV()
Dim ChrArray As Variant
Dim Data() As Byte
Dim FileFilter As String
Dim FileName As Variant
Dim n As Long
Dim Rng As Range
Dim Text As String
Set Rng = Range("B2:B2")
FileFilter = "Comma Separated Values (*.csv),*.csv"
FileName = Application.GetOpenFilename(FileFilter)
If FileName = False Then Exit Sub
Open FileName For Binary Access Read As #1
ReDim Data(LOF(1))
Get #1, , Data
Close #1
Text = StrConv(Data, vbUnicode)
Text = Replace(Text, vbCrLf, ",")
ChrArray = Split(Text, ",")
For n = 29 To UBound(ChrArray) - 1 Step 32
Rng.Cells(1, 0) = ChrArray(n)
Set Rng = Rng.Offset(1, 0)
Next n
End Sub
I'll be very greatful to anyone who can help me with this since my boss needs it ASAP :/
Regards,
Alex