Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have an excel spreadsheet with data set up in four different columns.
Sample data below: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish Start 45, 45 42, 43 Finish Start 78, 34 12, 34 Finish Start 45, 67 96, 23 Finish Start 96, 23 45, 56 Finish Start 56, 56 45, 45 Finish Start 78, 34 78, 34 Finish Start 12, 34 45, 56 Finish I need to export those four columns of data to a text file, but need it to end up in the the following format, with each cell on the next line: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish I'm currently using column Q-T on a sheet named "Data". Each week there is a different number of rows, so I just need all rows containing data to be addressed. Can anyone help? Thanks! Dani |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dani,
Try this. The purpose of this line If Dir(targetfile) < "" Then Kill targetfile is to delete your text file if it already exists Sub Marine() Dim LastRow As Long Set sht = Sheets("Data") saveDir = "C:\" 'Change to suit targetfile = saveDir & "MyFile.txt" 'Change to suit LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row If Dir(targetfile) < "" Then Kill targetfile Open targetfile For Output As #1 Set MyRange = sht.Range("Q1:Q" & LastRow) For Each c In MyRange Print #1, c.Value For x = 1 To 3 Print #1, c.Offset(, x).Value Next Next Close #1 End Sub -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Dani" wrote: I have an excel spreadsheet with data set up in four different columns. Sample data below: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish Start 45, 45 42, 43 Finish Start 78, 34 12, 34 Finish Start 45, 67 96, 23 Finish Start 96, 23 45, 56 Finish Start 56, 56 45, 45 Finish Start 78, 34 78, 34 Finish Start 12, 34 45, 56 Finish I need to export those four columns of data to a text file, but need it to end up in the the following format, with each cell on the next line: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish I'm currently using column Q-T on a sheet named "Data". Each week there is a different number of rows, so I just need all rows containing data to be addressed. Can anyone help? Thanks! Dani |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Works perfectly! Thanks, Mike!
"Mike H" wrote: Dani, Try this. The purpose of this line If Dir(targetfile) < "" Then Kill targetfile is to delete your text file if it already exists Sub Marine() Dim LastRow As Long Set sht = Sheets("Data") saveDir = "C:\" 'Change to suit targetfile = saveDir & "MyFile.txt" 'Change to suit LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row If Dir(targetfile) < "" Then Kill targetfile Open targetfile For Output As #1 Set MyRange = sht.Range("Q1:Q" & LastRow) For Each c In MyRange Print #1, c.Value For x = 1 To 3 Print #1, c.Offset(, x).Value Next Next Close #1 End Sub -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Dani" wrote: I have an excel spreadsheet with data set up in four different columns. Sample data below: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish Start 45, 45 42, 43 Finish Start 78, 34 12, 34 Finish Start 45, 67 96, 23 Finish Start 96, 23 45, 56 Finish Start 56, 56 45, 45 Finish Start 78, 34 78, 34 Finish Start 12, 34 45, 56 Finish I need to export those four columns of data to a text file, but need it to end up in the the following format, with each cell on the next line: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish I'm currently using column Q-T on a sheet named "Data". Each week there is a different number of rows, so I just need all rows containing data to be addressed. Can anyone help? Thanks! Dani |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your welcome and thanks for the feedback
-- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Dani" wrote: Works perfectly! Thanks, Mike! "Mike H" wrote: Dani, Try this. The purpose of this line If Dir(targetfile) < "" Then Kill targetfile is to delete your text file if it already exists Sub Marine() Dim LastRow As Long Set sht = Sheets("Data") saveDir = "C:\" 'Change to suit targetfile = saveDir & "MyFile.txt" 'Change to suit LastRow = sht.Cells(Cells.Rows.Count, "Q").End(xlUp).Row If Dir(targetfile) < "" Then Kill targetfile Open targetfile For Output As #1 Set MyRange = sht.Range("Q1:Q" & LastRow) For Each c In MyRange Print #1, c.Value For x = 1 To 3 Print #1, c.Offset(, x).Value Next Next Close #1 End Sub -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Dani" wrote: I have an excel spreadsheet with data set up in four different columns. Sample data below: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish Start 45, 45 42, 43 Finish Start 78, 34 12, 34 Finish Start 45, 67 96, 23 Finish Start 96, 23 45, 56 Finish Start 56, 56 45, 45 Finish Start 78, 34 78, 34 Finish Start 12, 34 45, 56 Finish I need to export those four columns of data to a text file, but need it to end up in the the following format, with each cell on the next line: Start 42, 43 56, 56 Finish Start 12, 34 45, 45 Finish Start 45, 56 78, 34 Finish I'm currently using column Q-T on a sheet named "Data". Each week there is a different number of rows, so I just need all rows containing data to be addressed. Can anyone help? Thanks! Dani |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Exporting Excel file into Notepad with column & row lines | Charts and Charting in Excel | |||
Exporting to a CSV file from multiple worksheets | Excel Programming | |||
Exporting to txt file, how to insert a "Enter" between lines | Excel Programming | |||
excel97 vba to append lines to text file overwriting last 2 lines | Excel Programming | |||
Exporting from multiple worksheets to single text file | Excel Programming |