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?
Bookmarks