Results 1 to 3 of 3

Thread: Exel cell

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    28

    Exel cell

    Once again i find myself in need of help.

    Exel has the habbit to 'change' cells if they have a number of numbers.
    The number added into the cell changes to like 1.025EEE.
    Does not happen if you add letters instead of numbers

    Dim oXLApp As Excel.Application 'Declare the object variables
    Dim oXLBook As Excel.Workbook
    Set oXLApp = New Excel.Application 'Create a new instance of Excel
    Set oXLBook = oXLApp.Workbooks.Add 'Add a new workbook
    oXLApp.Visible = True 'Show it to the user
    Set oXLBook = oXLApp.Workbooks.Add 'Add a new workbook
    Set oXLApp = Nothing
    Set oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet ??????????????????????? NODIG OF NIET

    Open "ONTKEN" For Random As #5 Len = Len(NOTmE)
    bestandlengte = LOF(5) / 177

    Get 5, bestandlengte, NOTmE

    For I = 1 To bestandlengte
    Get 5, I, NOTmE
    oXLSheet.Cells(I, 1).Value = Trim(NOTmE.dDAG) ' dagnummer invullen''' 1 omlaag 1 rechts
    oXLSheet.Cells(I, 2).Value = Trim(NOTmE.dDATUM) 'datum invullen
    oXLSheet.Cells(I, 3).Value = Trim(NOTmE.dDOSSIER) 'dossier invullen
    oXLSheet.Cells(I, 4).Value = Trim(NOTmE.dZMAAND) 'maand invullen
    oXLSheet.Cells(I, 5).Value = Trim(NOTmE.dZJAAR) 'jaar invullen
    oXLSheet.Cells(I, 6).Value = Trim(NOTmE.dZTIJD) 'tijd invullen
    oXLSheet.Cells(I, 7).Value = Trim(NOTmE.dAWB) ' 12 digit number waybilnummer invullen <<<<<<< this one goes wrong
    oXLSheet.Cells(I, 8).Value = Trim(NOTmE.dcOMBO1) 'naam invullen
    I = I + 1
    Next

    Set oXLBook = Nothing 'Disconnect from Excel (let the user take over)
    Set oXLApp = Nothing

    I tried changing .Value = into .Text but that dont help
    How do i get exel to accept this 12 digit number without 'changing it' ??????

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Exel cell

    There are two main ways, one is to tell Excel to display it in the way you want (manually it is via "Format Cells", code is .NumberFormat), the other is to force it to be text by adding the ' character in front of the value:
    Code:
    oXLSheet.Cells(I, 7).Value = "'" & Trim(NOTmE.dAWB)

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Exel cell

    If you want to convert number to text then do what si_the_geek mentioned, otherwise:

    * When cell format is General (default with new created worksheet), with large number (12 digits in this case), if column width is not wide enough, Excel will display the number in scientific notation such as 1.025E11.
    * If set .NumberFormat of the cell to "0" and column width is also not wide enough, the number will display as ########.
    * Set the width of column G larger, the number will be displayed in full of 12 digits.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

Posting Permissions

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



Click Here to Expand Forum to Full Width