+ Reply to Thread
Results 1 to 2 of 2

Export Data to *.txt or *prn. Text file to have equal field spacing.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2008
    Location
    Leamington Spa, UK
    MS-Off Ver
    2010
    Posts
    142

    Question Export Data to *.txt or *prn. Text file to have equal field spacing.

    Hi All,

    I have to export columns A:J to a text, prn or similar text file. However I require the data from these cells to be exported such that in the text file they align with fields in the text file. By fields I mean the data from cell A1 must be written to the text file within the first 10 spaces of the text file. Data from cell A2 must be written within the 11th space to the 20th space. Data from cell A3 must be written within the 21th space to the 30th space... And so on.

    If it helps:
    $23456789!123456789!123456789!123456789!123456789!123456789!123456789!123456789!123456789!123456789!
    A1_Data ! A2_Data! A3_Data! A4_Data!...
    Appologies for the above example the spacing of a 'space' seems to vary. It is important that info within the first 10 spaces (from data of cell A1) of the text are LHS justified, while the other 9 fields are RHS justified.

    Obviously the maximum data that can be exported from any 1 cell is 10 characters.

    Hopefully that makes some sense...?

    The data is required to be used as an input deck for a piece of software.

    If anyone can help me out with the above i'd greatly appreciate it!

    Cheers

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    I'm hoping that you want to take each row and output it, not each column...

    Sub yyy()
      Open "c:\temp\rs6.txt" For Output As #1
      
      For Each ce In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        strr = Left(ce.Value & "          ", 10)
        
        For i = 1 To 9
          strr = strr & Right("          " & ce.Offset(0, i), 10)
        Next i
        Print #1, strr
      Next ce
      
      Close #1
    End Sub
    rylo

+ 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