+ Reply to Thread
Results 1 to 9 of 9

Number in decimal Format in text file generate from Excel VBA

  1. #1
    Registered User
    Join Date
    04-17-2016
    Location
    Dhaka
    MS-Off Ver
    2007
    Posts
    8

    Number in decimal Format in text file generate from Excel VBA

    Hi, I have searched a lot but find no answer. Hope someone helps me in this context.
    I am using a vba code to create a text file from an excel sheet. The code works fine. But there is a number format in decimal in excel which converts as a number without a decimal place in the text file. below is the code I used.
    Please Login or Register  to view this content.
    Hope someone helps me to overcome my difficulties.

    Thanks in advance

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    862

    Re: Number in decimal Format in text file generate from Excel VBA

    a sample file will go a long way in assisting with your issues. Follow the steps in the yellow banner on how to upload.

    Why are you not applying the format to the "Else" line as well?
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  3. #3
    Registered User
    Join Date
    04-17-2016
    Location
    Dhaka
    MS-Off Ver
    2007
    Posts
    8

    Re: Number in decimal Format in text file generate from Excel VBA

    Thanks for your response.

    All data in the excel file is in text format only one column of data is in number format like e.g. 6000.00
    After the text file generates the number data look like 6000.

    applying the format to the "Else" line gives me the same result.

    Thanks

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    14,336

    Re: Number in decimal Format in text file generate from Excel VBA

    The number 6000 formatted as 0.00 displays as 6000.00, but the underlying value is still 6000. I don't see anything in your code that attempts to write the numeric value as text in a certain number format.

    I can't tell where in the code it belongs, but I think you need to include a Format() function somewhere in the VBA procedure to convert the number in the cell (6000) to the text string ("6000.00") before or while writing the text to the text file.

    Format() function help file: https://docs.microsoft.com/en-us/off...r-applications
    Example: mytext=Format(6000,"0.00") 'mytext would contain the text string "6000.00".
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    04-17-2016
    Location
    Dhaka
    MS-Off Ver
    2007
    Posts
    8

    Re: Number in decimal Format in text file generate from Excel VBA

    A sample file is attached.
    Its Created the TD.text file but I want the text file as "Expected Result.txt" file content.

    Hope for the best.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    14,336

    Re: Number in decimal Format in text file generate from Excel VBA

    I don't have a way to test right now, but, as I indicated, I think you need a Format() function somewhere in there. I Might guess that it belongs here:
    Please Login or Register  to view this content.
    How did I do without being able to test it?

  7. #7
    Registered User
    Join Date
    04-17-2016
    Location
    Dhaka
    MS-Off Ver
    2007
    Posts
    8

    Re: Number in decimal Format in text file generate from Excel VBA

    I don't understand your question "How did I do without being able to test it?". I tried the above code but it debugging. If I remove the Stop 'For debugging purposes the result is the same as before.

    Thanks

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    6,565

    Question Re: Number in decimal Format in text file generate from Excel VBA


    Hi,

    what is your system decimal separator ?

  9. #9
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Number in decimal Format in text file generate from Excel VBA

    Give it a try. Just change the path

    Please Login or Register  to view this content.
    Messages have been translated from Dutch to English by means of google translate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2020, 03:53 PM
  2. [SOLVED] Number decimal does not disply as "Text" format
    By jtlayne1969 in forum Excel General
    Replies: 4
    Last Post: 09-05-2019, 01:31 PM
  3. Replies: 3
    Last Post: 05-18-2016, 09:38 AM
  4. Keep number format when converting to text - with decimal and zeros
    By tampagirl in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-11-2014, 06:34 PM
  5. Use Excel to generate a text file
    By julius.nkemdiche in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-20-2013, 07:30 PM
  6. Convert Number in Text format to Value with decimal
    By MAHMUZ in forum Excel General
    Replies: 4
    Last Post: 09-15-2010, 10:28 AM
  7. [SOLVED] How can Excel generate more decimal points ie 5.5% not 5%
    By helpmeplease in forum Excel General
    Replies: 2
    Last Post: 06-09-2006, 01:10 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1