Hello all,
What I am trying to do is append a range on my spreadsheet to a csv file. I found this code, it works but it appends everything in one row. I want it to be in 2 columns in the csv file.
Any help would be awesome.
thanks
![]()
Sub Append2CSV() Dim tmpCSV As String 'string to hold the CSV info Dim f As Integer Const CSVFile As String = "C:\test.csv" 'replace with your filename f = FreeFile Open CSVFile For Append As #f tmpCSV = Range2CSV(Range("A1:B10")) Print #f, tmpCSV Close #f End Sub Function Range2CSV(list) As String Dim tmp As String Dim cr As Long Dim r As Range If TypeName(list) = "Range" Then cr = 1 For Each r In list.Cells If r.Row = cr Then If tmp = vbNullString Then tmp = r.Value Else tmp = tmp & "," & r.Value End If Else cr = cr + 1 If tmp = vbNullString Then tmp = r.Value Else tmp = tmp & Chr(10) & r.Value End If End If Next End If
Bookmarks