Freshman
Registered User.
- Local time
- Tomorrow, 00:50
- Joined
- May 21, 2010
- Messages
- 437
Hi all,
I have a csv file that I download and then import into an Access db.
There are around 100,000 rows
One of the columns contains a serial number which could look like a number or text. Some containing only number and others a fix of letters, numbers and even symbols.
After importing it I have problems with some values failing (not showing or showing as huge number with 'to the power' at the end)
I played around with converting it to xlsx and also with using NumberFormat = "@" and all other options like ";;" or "#######" or "000000" and the rest.
With some options some of the values are correct but others not and visa versa. I thought the text option "@" would cover all bases but it is not.
After a few hours of trying all sorts I noticed that the sure one that succeeds is if I put a single quote ' in front of all the values in the column before importing it.
I do the above before importing it using docmd.tranferspreadsheet
I tried this in code but it take forever. Not practical
I'm open to idea. Maybe a replace function or concat or some idea that will do it faster.
Or some tips on why I can't seem to get a good one-fit-for-all NumberFormat option.
Thanks
FM
I have a csv file that I download and then import into an Access db.
There are around 100,000 rows
One of the columns contains a serial number which could look like a number or text. Some containing only number and others a fix of letters, numbers and even symbols.
After importing it I have problems with some values failing (not showing or showing as huge number with 'to the power' at the end)
I played around with converting it to xlsx and also with using NumberFormat = "@" and all other options like ";;" or "#######" or "000000" and the rest.
With some options some of the values are correct but others not and visa versa. I thought the text option "@" would cover all bases but it is not.
After a few hours of trying all sorts I noticed that the sure one that succeeds is if I put a single quote ' in front of all the values in the column before importing it.
I do the above before importing it using docmd.tranferspreadsheet
I tried this in code but it take forever. Not practical
Code:
Public Function Test()
'On Error GoTo Err_FixLN
Dim wb As Object
Dim xlApp As Object
Dim rng As Range
Set xlApp = CreateObject("Excel.Application")
''xlApp.Visible = True
Set wb = xlApp.Workbooks.Open("C:\CL.xlsx", True, False)
Set rng = wb.ActiveSheet.Range("B:B")
totrows = rng.rows.Count()
For n = 2 To totrows
rng.Cells(n, 1).Value = "'" & rng.Cells(n, 1).Value
Next n
wb.Save
wb.Close
xlApp.Quit
MsgBox "Done"
Exit Function
Err_FixLN:
MsgBox "Error", vbInformation, "Notice"
End Function
I'm open to idea. Maybe a replace function or concat or some idea that will do it faster.
Or some tips on why I can't seem to get a good one-fit-for-all NumberFormat option.
Thanks
FM