Hi all, i need help writing a macro that copies specific data from each row of a workbook and puts it into a separate dat file for each row. So far i was able to write something up that only works for the first row(seconf beneath header). How can i modify this to export each row on a separate file - again, having some custom ordering applied same as i do below
Sample data:
[TABLE="width: 358"]
<tbody>[TR]
[TD]Project name[/TD]
[TD]Client[/TD]
[TD]First name[/TD]
[TD]Last name[/TD]
[TD]userid[/TD]
[/TR]
[TR]
[TD]JHGH[/TD]
[TD]Nike[/TD]
[TD]John[/TD]
[TD]Doe[/TD]
[TD]johnd[/TD]
[/TR]
[TR]
[TD]VBNM[/TD]
[TD]Coca Cola[/TD]
[TD]Jane[/TD]
[TD]Doe[/TD]
[TD]janed2[/TD]
[/TR]
</tbody>[/TABLE]
Sample data:
[TABLE="width: 358"]
<tbody>[TR]
[TD]Project name[/TD]
[TD]Client[/TD]
[TD]First name[/TD]
[TD]Last name[/TD]
[TD]userid[/TD]
[/TR]
[TR]
[TD]JHGH[/TD]
[TD]Nike[/TD]
[TD]John[/TD]
[TD]Doe[/TD]
[TD]johnd[/TD]
[/TR]
[TR]
[TD]VBNM[/TD]
[TD]Coca Cola[/TD]
[TD]Jane[/TD]
[TD]Doe[/TD]
[TD]janed2[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Option Explicit
Sub TEST()
Dim fso As Object, opStr As String
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object, fPath As String
fPath = ThisWorkbook.Path & "\" & Data.Range("A2") & "-" & Format(Now, "MM.DD.YYYY") & ".dat"
Set Fileout = fso.CreateTextFile(fPath, True, True)
opStr = "SOME HARDCODED TEXT &" _
& Data.Range("A2") & "|" & Data.Range("B2") & "|" & Data.Range("C2") & "|" & Data.Range("D2")
Fileout.Write opStr
Fileout.Close
MsgBox "Done. File: " & fPath
End Sub