Hi guys,
I'm trying to import a csv file to Excel & forcing the cells to be text fields so that numeric values don't loose leading zero's. Unfortunately the code I have is importing all of the lines in the csv to row 1. I would apreciate some help to show me what I am missing to split the file correctly.
I'm trying to import a csv file to Excel & forcing the cells to be text fields so that numeric values don't loose leading zero's. Unfortunately the code I have is importing all of the lines in the csv to row 1. I would apreciate some help to show me what I am missing to split the file correctly.
Code:
Sub import()
Dim myF As String, txt As String, x, a(), n As Long, ff As Integer, i As Long
myF = "C:\test.csv"
ff = FreeFile
Open myF For Input As #ff
Do While Not EOF(ff)
Line Input #ff, txt
x = Split(txt, ",")
n = n + 1
ReDim Preserve a(1 To n)
a(n) = x
Loop
Close #ff
With ThisWorkbook.Sheets(1)
.Cells.NumberFormat = "@"
With .Range("a1")
For i = 1 To n
.Offset(i - 1).Resize(, UBound(a(i)) + 1).Value = a(i)
.Offset(3, 1).Select
Next
End With
End With
End Sub