Results 1 to 8 of 8

Thread: formatting number in csv file import. Number being rounded / decimnal places truncated

  1. #1
    Junior Member
    Join Date
    Aug 2021
    Posts
    10
    Rep Power
    0

    formatting number in csv file import. Number being rounded / decimnal places truncated

    Hi,

    have the code below when importing csv file the invoice # with 12 digits get imported like this "4.00003E+11
    " when the number should imported like this "400003395647" please help to modify the code that import the correct number.


    here is the code:


    Code:
    Sub ImportRawData()
     
        Dim c           As Long
        Dim Col         As Variant
        Dim Filename    As String
        Dim Filepath    As Variant
        Dim rngBeg      As Range
        Dim rngEnd      As Range
        Dim rngDst      As Range
        Dim rngSrc      As Range
        Dim rowsize     As Long
        Dim wkbDst      As Workbook
        Dim wkbSrc      As Workbook
        Dim vFile
        
        vFile = Application.GetOpenFilename("CSV Files(*.csv),*.csv", , "please select a file", MultiSelect:=False)
    
    
        
            Set wkbDst = ThisWorkbook
            Set rngDst = wkbDst.Worksheets("STATEMENT").Range("A17:E17")
            
            Filepath = "C:\Users\jose.rossi\Desktop\AP_NCL_VENDOR STATEMENT.xlsm"
            Filename = "apvtrn.csv"
            
            On Error Resume Next
                Set wkbSrc = Workbooks(Filename)
                If Err = 9 Then
                    If Filepath <> "" Then ChDir Filepath Else ChDir ThisWorkbook.Path
                    'Filename = Application.GetOpenFilename("Excel Workbooks, *.xlsx")
                    If Filename = "False" Then Exit Sub
                    Set wkbSrc = Workbooks.Open(Filename)
                End If
            On Error GoTo 0
            
            ' Clear previous data.
            'rngDst.Resize(rngDst.Parent.UsedRange.Rows.Count).ClearContents
            
            ' Import the data.
            With wkbSrc.Worksheets("apvtrn").UsedRange
                ' Step through the source data columns.
                For Each Col In Array("DM", "DI", "DN", "DP", "DQ")
           
    ' Data starts on row 1.
                    Set rngBeg = .Parent.Cells(1, Col)
                    
                    ' Find the row where the data ends in this column.
                    Set rngEnd = .Parent.Cells(Rows.Count, Col).End(xlUp)
                    
                    ' Number of rows in this column.
                    rowsize = rngEnd.Row - rngBeg.Row
                    
                    If rowsize > 0 Then
                        Set rngSrc = .Parent.Range(rngBeg, rngEnd)
                                         
                       rngDst.Offset(0, c).Resize(rowsize, 1).Value = rngSrc.Value
                    End If
                    
                    ' Increment the column offset.
                    c = c + 1
                Next Col
            End With
            
    End Sub
    Thank you,

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,378
    Rep Power
    10
    Hello again

    I think it may be a lot easier for someone at excelfox to help you if we can have a copy of your workbook, and some data in a small .csv file

    So we need to have
    _ a copy of your workbook which has worksheet "STATEMENT" in it
    _ a csv file, apvtrn.csv


    Please change or remove any sensitive data. Please try to keep the data size small: We only need a small amount of data – we only need as much data as necessary to demonstrates the problem.

    ( here are some notes on attaching a file at excelfox
    https://excelfox.com/forum/showthrea...ll=1#post11279
    https://excelfox.com/forum/showthrea...ll=1#post15589
    )




    Alan
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  3. #3
    Junior Member
    Join Date
    Aug 2021
    Posts
    10
    Rep Power
    0

    CSV FORMAT

    Hi

    files attached.

    i had to save the apvtrn.csv file as xls format will not let attach csv file.



    thank you,
    Attached Files Attached Files

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,378
    Rep Power
    10
    Thanks for the files.
    Please could you try to upload the csv file again as a csv file. - I have changed the system so that you should now be able to upload csv files
    ( I did test, and I think now we can upload csv files at excelfox )
    Thanks
    Alan
    Last edited by DocAElstein; 08-18-2021 at 12:02 AM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  5. #5
    Junior Member
    Join Date
    Aug 2021
    Posts
    10
    Rep Power
    0

    csv number format

    Done.

    attached in csv format.

    Thank you,
    Attached Files Attached Files

  6. #6
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,378
    Rep Power
    10
    Hi

    The numbers appear to be imported correctly.
    I looked in your .csv text file :
    https://excelfox.com/forum/showthrea...ll=1#post15602
    https://excelfox.com/forum/showthrea...ll=1#post15603
    https://i.imgur.com/PgEalNM.jpg
    LargeNumbersImportedCorrectly.JPG
    _____ Workbook: apvtrn.csv ( Using Excel 2007 32 bit )
    Row\Col
    DI
    1
    PY00000000000000004918
    2
    4.00E+11
    3
    PY00000000000000005064
    4
    4.00E+11
    5
    PY00000000000000005149
    6
    4.00E+11
    7
    PY00000000000000005260
    8
    4.00E+11
    9
    PY00000000000000005453
    Worksheet: apvtrn

    There are no numbers like "400003395647"

    If you have a text file with data that cause the problem, please gives us a sample of that. ( Remember to please keep the sample file size small - we only need 2-3 lines of data in order to investigate the problem. But the data must be chosen so as to demonstrate the problem )

    Alan
    Last edited by DocAElstein; 08-18-2021 at 05:57 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

  7. #7
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    11
    I suspect the csv file has been saved from Excel as a csv file, so Excel has already mangled it.
    What version of Excel are you using?
    You could record a macro of you using the Text Import wizard, where you'll be able to choose the 5 columns you want to import as well as ensure that the account numbers are imported as text and convert the date columns to real dates. Then it'll be a matter of tweaking the recorded macro for more general use.
    If you have Get & Transform Data (Power Query) which is built in to the more recent versions of Excel you'll be able extract, transform and load your data exactly as you want it.

  8. #8
    Junior Member
    Join Date
    Aug 2021
    Posts
    10
    Rep Power
    0
    thank you for your suggestion will do that going forward.

Similar Threads

  1. Replies: 12
    Last Post: 07-05-2020, 03:57 PM
  2. Replies: 26
    Last Post: 07-17-2013, 11:42 AM
  3. Replies: 4
    Last Post: 06-20-2013, 04:25 PM
  4. Replies: 3
    Last Post: 03-31-2013, 06:18 AM
  5. Adding specfic number to a available number in previous cell.
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 2
    Last Post: 03-02-2013, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •