+ Reply to Thread
Results 1 to 4 of 4

Outputting to text files to include carriage returns

  1. #1
    Registered User
    Join Date
    09-20-2017
    Location
    England
    MS-Off Ver
    2010
    Posts
    3

    Outputting to text files to include carriage returns

    Hi I have the following line of code in one excel cell
    "01VINV20160229130801Jan 16 Incentive700120160101Incentive for Jan 16 GBP
    02VINV20160229130801Jan 16 IncentiveZP00655 20160101ZE07110 Incentive for Jan 16
    04VINV20160229130801Jan 16 Incentive0000514060110 0 V0MWFS Jan 16 Incentive "


    This is derived from the following formula:


    ='Copy of Payment file format'!A3&'Copy of Payment file format'!B3&'Copy of Payment file format'!C3&'Copy of Payment file format'!D3&'Copy of Payment file format'!E3&'Copy of Payment file format'!F3&'Copy of Payment file format'!G3&'Copy of Payment file

    I want to be able to save to a text file so it generates 3 lines of data, is this possible?

    thanks
    Carl.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Outputting to text files to include carriage returns

    Check if this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    (may be location of addec character 10 shall be different - I do not know the content of your file cells)

    PS. Make sure the cell is formatted to wrap text
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    09-20-2017
    Location
    England
    MS-Off Ver
    2010
    Posts
    3

    Re: Outputting to text files to include carriage returns

    I'm trying this vba - its almost there but doing something funny

    Sub writetexttofile()

    Dim filepath As String
    Dim celldata As String
    Dim lastcol As Long
    Dim lastrow As Long
    Dim firstrow As Long

    lastcol = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Column
    lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
    'firstrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeFirstCell).Row

    'celldata = ""

    filepath = "c:\testpayment.txt"

    Open filepath For Output As #2

    For i = 1 To lastrow


    For j = 1 To lastcol

    If j = lastcol Then
    celldata = Left((ActiveCell(i, j).Value), 80) & vbCrLf & Mid((ActiveCell(i, j).Value), 80, 123) & vbCrLf & Right((ActiveCell(i, j).Value), 159)
    Else
    celldata = Left((ActiveCell(i, j).Value), 80) & vbCrLf & Mid((ActiveCell(i, j).Value), 80, 123) & vbCrLf & Right((ActiveCell(i, j).Value), 159)
    End If
    Next j

    Write #2, celldata

    Next i

    Close #2

    MsgBox ("Done")

    End Sub

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Outputting to text files to include carriage returns

    1) "doing something funny" is rather vague, please be more specific.
    2) please edit your post and use code tags around the code - see our Rule 3. (see below, how readability is improved, and note that there is handy option to copy all the code snippet into your clipboard)

    PS. Of course you can also write it piece by piece like:
    Please Login or Register  to view this content.
    and check if it looks better
    Last edited by Kaper; 09-20-2017 at 08:49 AM.

+ 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. Exporting to text file with carriage returns
    By carlmeads1975 in forum Excel General
    Replies: 2
    Last Post: 09-20-2017, 05:29 AM
  2. [SOLVED] Extracting text at the carriage returns without hidden characters
    By JimDandy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-23-2017, 12:20 PM
  3. [SOLVED] Referencing text fields with in cell carriage returns
    By cadmanweyland in forum Excel General
    Replies: 4
    Last Post: 04-18-2013, 09:41 PM
  4. [SOLVED] Clearing the carriage returns in a cell with text
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-05-2012, 11:59 AM
  5. Carriage Returns in files visible at work, not at home
    By teitoku in forum Excel General
    Replies: 2
    Last Post: 12-21-2010, 02:42 PM
  6. Replies: 1
    Last Post: 11-05-2010, 06:09 PM
  7. Replies: 3
    Last Post: 11-17-2005, 03:10 PM

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