I use adodb to import csv to sheet but i have problem with trailing minus data and it seem record set cannot recognize trailing minus and it disappear.
i want it to import negatve number but because they are trailing minus number, it doesn’t work. I can’t use query table because i want to work with large file and query table is too slow. I don’t want to work with power query too.
Here is a part of my code
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
Dim recordSet As Object
Set recordSet = CreateObject("ADODB.recordset")
'Create Schema file
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(strFilePath & "\Schema.ini")
oFile.WriteLine ("[" & strFileName & "]")
oFile.WriteLine ("Format=Delimited(;)")
oFile.WriteLine ("ColNameHeader=True")
oFile.WriteLine ("CharacterSet=OEM")
oFile.WriteLine ("MaxScanRows=25")
and i copy it to my sheet
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.connectionstring = "Data Source=" & strFilePath & ";Extended Properties=""text;HDR=YES;IMEX=1,FMT=Delimited(;)"""
End With
conn.Open
recordSet.Open "SELECT * from " & strFileName, conn, 3, 1
Dim copyRng As Range
Set copyRng = ws.Range("A2")
With ws
.UsedRange.ClearContents
.Range("A1:Z1") = headers
copyRng.CopyFromRecordset recordSet
...
end with
i want to include negative number to the sheet
đức anh phạm ngọc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.