Hi.
Hope anyone can help with this issue.
I have two sheets with one dynamic list i both sheets i would like to combine to one CSV file.
Today i am exporting one range from one sheet to a CSV file, usint the code below, and this works perfectly.
Now i would like to add data from another range from another sheet to this same CSV file.
The format and number of columns are exactly the same in both sheets.
Number of rows is dynamic.
I would like to include this range in to the CSV file also:
Sheet = "Sheet2"
Range = "A2:D2"
Public Sub Save_Range_CSV_COMBINED()
Dim cellData As Variant, i As Long, j As Long
Dim lines() As String
With Sheets("Produktionsordre")
cellData = .Range("A2:D2").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row).value
End With
ReDim lines(1 To UBound(cellData))
i = 1
For j = 1 To 4
lines(i) = lines(i) & cellData(i, j) & ","
Next
lines(i) = lines(i) & "LAGER"
For i = 2 To UBound(cellData)
For j = 1 To 4
lines(i) = lines(i) & cellData(i, j) & ","
Next
lines(i) = lines(i) & "LAGER"
Next
Open "C:\test\PROD " & Format(Now, "DD-MM-YYYY HH MM") & ".txt" For Output As #1
Print #1, Join(lines, vbCrLf)
Close #1
Dim csvFile As String
csvFile = "C:\test\PROD " & Format(Now, "DD-MM-YYYY HH MM") & ".txt"
Open csvFile For Output As #1
Print #1, Join(lines, vbCrLf)
Close #1
MsgBox "Filen er gemt: " & csvFile
End Sub
Hope anyone can help with this issue.
I have two sheets with one dynamic list i both sheets i would like to combine to one CSV file.
Today i am exporting one range from one sheet to a CSV file, usint the code below, and this works perfectly.
Now i would like to add data from another range from another sheet to this same CSV file.
The format and number of columns are exactly the same in both sheets.
Number of rows is dynamic.
I would like to include this range in to the CSV file also:
Sheet = "Sheet2"
Range = "A2:D2"
Public Sub Save_Range_CSV_COMBINED()
Dim cellData As Variant, i As Long, j As Long
Dim lines() As String
With Sheets("Produktionsordre")
cellData = .Range("A2:D2").Resize(.Cells(.Rows.Count, "A").End(xlUp).Row).value
End With
ReDim lines(1 To UBound(cellData))
i = 1
For j = 1 To 4
lines(i) = lines(i) & cellData(i, j) & ","
Next
lines(i) = lines(i) & "LAGER"
For i = 2 To UBound(cellData)
For j = 1 To 4
lines(i) = lines(i) & cellData(i, j) & ","
Next
lines(i) = lines(i) & "LAGER"
Next
Open "C:\test\PROD " & Format(Now, "DD-MM-YYYY HH MM") & ".txt" For Output As #1
Print #1, Join(lines, vbCrLf)
Close #1
Dim csvFile As String
csvFile = "C:\test\PROD " & Format(Now, "DD-MM-YYYY HH MM") & ".txt"
Open csvFile For Output As #1
Print #1, Join(lines, vbCrLf)
Close #1
MsgBox "Filen er gemt: " & csvFile
End Sub