Excel 2013
Layout:
Cell A1: stores the network drive letter (currently set as P
Cell A2: stores the name of the file (currently set as Test.txt)
Row 4 has column headings: 1st Value, 2nd Value, 3rd Value
Rows 5 to forever, but only Columns A, B & C have data in them. Currently I just have 1-2-3 in row 5, then 4-5-6 in row 6 and so on.
When I push the button with macro assigned to it, the data exports to the txt file as follows:
1,2,3,
4,5,6,
7,8,9,
10,11,12,
Here's the current VB Code:
Sub test()
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Selection.HorizontalAlignment = xlLeft
Range("B5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Selection.HorizontalAlignment = xlLeft
Range("C5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Range("A5").Select
Dim i As Long, r As Range, temp As String, txt As String
With Range("a5", Range("a" & Rows.Count).End(xlUp)).Resize(, 4)
For i = 1 To .Rows.Count
For Each r In .Rows(i).Cells
temp = temp & "," & r.Text
Next
txt = txt & vbCrLf & Mid$(temp, 2): temp = ""
Next
End With
Open Range("A1").Value & Range("A2").Value For Output As #1
Print #1 , Mid$(txt, Len(vbCrLf) + 1)
Close #1
MsgBox ("Done - File has been created & saved")
End Sub
My question is the following:
Is it possible to have the data exported as 1 continuous data set? Like the following:
1,2,3,4,5,6,7,8,9,10,11,12,
If it is possible, what would the code look like to make this work?
Layout:
Cell A1: stores the network drive letter (currently set as P
Cell A2: stores the name of the file (currently set as Test.txt)
Row 4 has column headings: 1st Value, 2nd Value, 3rd Value
Rows 5 to forever, but only Columns A, B & C have data in them. Currently I just have 1-2-3 in row 5, then 4-5-6 in row 6 and so on.
When I push the button with macro assigned to it, the data exports to the txt file as follows:
1,2,3,
4,5,6,
7,8,9,
10,11,12,
Here's the current VB Code:
Sub test()
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Selection.HorizontalAlignment = xlLeft
Range("B5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Selection.HorizontalAlignment = xlLeft
Range("C5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.NumberFormat = "General"
Range("A5").Select
Dim i As Long, r As Range, temp As String, txt As String
With Range("a5", Range("a" & Rows.Count).End(xlUp)).Resize(, 4)
For i = 1 To .Rows.Count
For Each r In .Rows(i).Cells
temp = temp & "," & r.Text
Next
txt = txt & vbCrLf & Mid$(temp, 2): temp = ""
Next
End With
Open Range("A1").Value & Range("A2").Value For Output As #1
Print #1 , Mid$(txt, Len(vbCrLf) + 1)
Close #1
MsgBox ("Done - File has been created & saved")
End Sub
My question is the following:
Is it possible to have the data exported as 1 continuous data set? Like the following:
1,2,3,4,5,6,7,8,9,10,11,12,
If it is possible, what would the code look like to make this work?