+ Reply to Thread
Results 1 to 5 of 5

Adding a comma after an int field

  1. #1
    Bennie
    Guest

    Adding a comma after an int field

    Hi

    I have a simple .xls worksheet with some VB code, spitting out a text file
    when you click a button to execute the code.

    I have int fields that I calculate as I create the file and at the end, I
    write the values of these fields to a trailer record.

    That all works OK, but now the requirement is to have a comma after the int
    value, so instead of having

    TOTALNUMBER=12
    TOTALVALUE=12345

    it should be
    TOTALNUMBER=12,
    TOTALVAULUE=12345,

    If I simply append a comma, I get this

    TOTALNUMBER=12 , <--- trailing spaces
    TOTALVALUE=12345 , <-- trailing spaces

    I've tried formatting it like this
    .transTotal = Format(Worksheets("Setup-tlr").Cells(30, 2).value, "######0")

    and then appending the comma but that does not work either. I tried adding a
    ',' to the mask (######0,) but that returns a zero value always.

    I appreciate any help - thanks!
    Bennie

  2. #2
    Gary''s Student
    Guest

    RE: Adding a comma after an int field

    Cells(30,2).NumberFormat = "General,"
    --
    Gary''s Student


    "Bennie" wrote:

    > Hi
    >
    > I have a simple .xls worksheet with some VB code, spitting out a text file
    > when you click a button to execute the code.
    >
    > I have int fields that I calculate as I create the file and at the end, I
    > write the values of these fields to a trailer record.
    >
    > That all works OK, but now the requirement is to have a comma after the int
    > value, so instead of having
    >
    > TOTALNUMBER=12
    > TOTALVALUE=12345
    >
    > it should be
    > TOTALNUMBER=12,
    > TOTALVAULUE=12345,
    >
    > If I simply append a comma, I get this
    >
    > TOTALNUMBER=12 , <--- trailing spaces
    > TOTALVALUE=12345 , <-- trailing spaces
    >
    > I've tried formatting it like this
    > .transTotal = Format(Worksheets("Setup-tlr").Cells(30, 2).value, "######0")
    >
    > and then appending the comma but that does not work either. I tried adding a
    > ',' to the mask (######0,) but that returns a zero value always.
    >
    > I appreciate any help - thanks!
    > Bennie


  3. #3
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    try adding <original line> & ","

    regards

  4. #4
    JE McGimpsey
    Guest

    Re: Adding a comma after an int field

    One way:

    .transtotal = Format(Trim( _
    Worksheets("Setup-tir").Cells(30, 2).Text), "######0\,")


    In article <48FDA59F-7A6D-4D1E-90AD-9BCC4ECF8DD7@microsoft.com>,
    Bennie <Bennie@discussions.microsoft.com> wrote:

    > Hi
    >
    > I have a simple .xls worksheet with some VB code, spitting out a text file
    > when you click a button to execute the code.
    >
    > I have int fields that I calculate as I create the file and at the end, I
    > write the values of these fields to a trailer record.
    >
    > That all works OK, but now the requirement is to have a comma after the int
    > value, so instead of having
    >
    > TOTALNUMBER=12
    > TOTALVALUE=12345
    >
    > it should be
    > TOTALNUMBER=12,
    > TOTALVAULUE=12345,
    >
    > If I simply append a comma, I get this
    >
    > TOTALNUMBER=12 , <--- trailing spaces
    > TOTALVALUE=12345 , <-- trailing spaces
    >
    > I've tried formatting it like this
    > .transTotal = Format(Worksheets("Setup-tlr").Cells(30, 2).value, "######0")
    >
    > and then appending the comma but that does not work either. I tried adding a
    > ',' to the mask (######0,) but that returns a zero value always.
    >
    > I appreciate any help - thanks!
    > Bennie


  5. #5
    Bennie
    Guest

    RE: Adding a comma after an int field

    Thanks to all who responded.

    I ended up using a free cell with a formula like

    =A1&","

    which did the trick.
    --
    Appreciated.
    Bennie


    "Bennie" wrote:

    > Hi
    >
    > I have a simple .xls worksheet with some VB code, spitting out a text file
    > when you click a button to execute the code.
    >
    > I have int fields that I calculate as I create the file and at the end, I
    > write the values of these fields to a trailer record.
    >
    > That all works OK, but now the requirement is to have a comma after the int
    > value, so instead of having
    >
    > TOTALNUMBER=12
    > TOTALVALUE=12345
    >
    > it should be
    > TOTALNUMBER=12,
    > TOTALVAULUE=12345,
    >
    > If I simply append a comma, I get this
    >
    > TOTALNUMBER=12 , <--- trailing spaces
    > TOTALVALUE=12345 , <-- trailing spaces
    >
    > I've tried formatting it like this
    > .transTotal = Format(Worksheets("Setup-tlr").Cells(30, 2).value, "######0")
    >
    > and then appending the comma but that does not work either. I tried adding a
    > ',' to the mask (######0,) but that returns a zero value always.
    >
    > I appreciate any help - thanks!
    > Bennie


+ 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