Results 1 to 12 of 12

Export matrix to single text

Threaded View

  1. #1
    Registered User
    Join Date
    05-08-2009
    Location
    Yogya
    MS-Off Ver
    Excel 2007
    Posts
    96

    Export matrix to single text

    This should be a piece of cake for you guys...

    Sub Text_Export()
        Dim strDeskTop As String
        Dim objWSH As Object
        Dim rngData As Range
        Dim lngRow As Long
        Dim lngCol As Long
        Dim strFileName As String
        Dim strBuffer As String
        Dim intUnit As Integer
        
        Set objWSH = CreateObject("WScript.Shell")
        strDeskTop = objWSH.SpecialFolders("Desktop") & "\Thesis\Route_Database_Numbers\"
        
        Set rngData = ActiveSheet.Range("A1").CurrentRegion
        
        For lngCol = 2 To rngData.Columns.Count
            strFileName = strDeskTop & rngData.Cells(lngCol, 1).Text & ".txt"
            intUnit = FreeFile
            Open strFileName For Output As intUnit
            strBuffer = ""
            For lngRow = 2 To rngData.Rows.Count
                strBuffer = strBuffer & rngData.Cells(lngCol, lngRow).Text
            Next
            Print #intUnit, Left(strBuffer, Len(strBuffer))
            Close intUnit
        Next
        
        Set objWHS = Nothing
        
    End Sub
    The code above will produce text files from a square matrix with the first column as the text file name,
    and the each row from the second row as the content of the corresponding title (from column 1).. e.g:



    	1	2	3
    1	a	t	y
    2	d	v	j
    3	e	u	k
    From that matrix we'll get :

    1.txt, contains aty
    2.txt, contains dvy
    3.txt, contains euk

    Now i want to modificate the code so that it would create a single text file, with all the matrix cells as the content..
    (the title doesn't matter, as it's only one file) e.g:


    one.txt , contains atydvyeuk
    I've been switching the "for.. next" in the code but i can't seem to get the right result

    thanks in advance.
    Last edited by Kb24; 09-03-2009 at 02:37 PM.

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