Results 1 to 6 of 6

extract data to a txt file

Threaded View

  1. #1
    Registered User
    Join Date
    06-18-2013
    Location
    Belgium
    MS-Off Ver
    Excel 2003, Excel 2013
    Posts
    4

    extract data to a txt file

    Hello all

    I would like a macro that creates a txt file with selected data from a table. In the example i have, there is a small table in the sheet "data" (3 columns : first name, last name, points). Some lines are copied to the sheet "copysheet". The lines for which column C is = 0 must not be copied, but must end up in a log file. This log file should look like :

    These people have 0 points :
    Eve
    John

    Now for the code. I have managed to copy rows for which column C is greater than 0. I have found how to create a txt file, but my txt file only shows the forst line, and no data at all...

    Sub logfile()
        
        Dim sFile As String
        Dim sText As String
        Dim iFileNum As Integer
        
        sText = "These people have 0 points :" & vbCrLf
    
        testselection "data", "A2:C2", "copysheet", "A2"
        testselection "data", "A3:C3", "copysheet", "A3"
        testselection "data", "A4:C4", "copysheet", "A4"
        testselection "data", "A5:C5", "copysheet", "A5"
        
        sFile = "C:\Documents and Settings\u936051\My Documents\Textfile" & Format(Now(), "yyyyMMdd_hhmmss") & ".txt"
        
        iFileNum = FreeFile
        Open sFile For Output As iFileNum
            Print #iFileNum, sText
        Close #iFileNum
        
    End Sub
    _____________________________________________________________________
    
    Sub testselection(OriginSheet As String, OriginRange As String, DestinSheet As String, DestinCell As String)
    
        Sheets(OriginSheet).Select
        Range(OriginRange).Select
        
        If ActiveCell.Offset(0, 2).Value > "0" Then
            Selection.Copy
            Sheets(DestinSheet).Activate
            Range(DestinCell).Select
            ActiveSheet.Paste
        Else
            sText = sText & ActiveCell.Value
        End If
        
    End Sub
    I guess the line that's not working is the last one of the second sub.
    Can someone tell me why?
    Last edited by AnnickW; 08-15-2013 at 12:11 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Wanted to extract data from a file which is already an excel macro file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2013, 11:43 AM
  2. How to extract Information from an Excel File and entering those data in a text file?
    By bikash.nitk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2012, 12:13 PM
  3. Replies: 1
    Last Post: 07-31-2011, 08:24 PM
  4. Extract data from one xls file to another
    By jguilfoyle in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-26-2009, 07:57 AM
  5. Extract data from xml file
    By ymeyaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2006, 01:50 AM

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