+ Reply to Thread
Results 1 to 4 of 4

Formatting number output to a text file

  1. #1
    Registered User
    Join Date
    06-30-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Formatting number output to a text file

    I am trying to write columns of number data from a worksheet into a text file. The data needs to be written in a specific format, and I have it stored in an array, x. I need to write it so that the first character is either a '-' (if the number is negative) or a space, followed by a single digit, a decimal point, then 6 decimal places, i.e. x0.000000, where x is either a '-' or a space. The data is all definitely between -9.999999 and 9.999999, so will fit into this format. I have tried outputting it as number format, or storing it in a string and outputting that, but I cannot get the space in-front of a positive number. Assuming that x is 1, I can either get the output as "1.000000" or "01.000000", but not " 1.000000".

    I have tried:
    Print #FNum, Format(x(j,i), "00.000000") and
    Print #FNum, Format(x(j,i), "#0.000000")

    And also putting the number into a string first:
    String1 = Format(x(j,i), "00.000000")
    String1 = Format(x(j,i), "@0.000000")
    String1 = Format(x(j,i), "#0.000000")
    String1 = Format(x(j,i), "&0.000000")

    None of these give me the output I need. Can anyone please tell me the correct format statement to use?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formatting number output to a text file

    Maybe you have to just test the number first:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 06-30-2012 at 01:22 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-30-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Formatting number output to a text file

    Brilliant, thanks very much for your help.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Formatting number output to a text file

    If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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