Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Exporting to text file in multiple lines

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Exporting to text file in multiple lines

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Exporting to text file in multiple lines

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Exporting to text file in multiple lines

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting Excel file into Notepad with column & row lines JIVL Charts and Charting in Excel 1 August 26th 08 12:14 AM
Exporting to a CSV file from multiple worksheets Neale[_2_] Excel Programming 0 May 31st 07 02:47 PM
Exporting to txt file, how to insert a "Enter" between lines fidller Excel Programming 2 July 17th 05 05:53 AM
excel97 vba to append lines to text file overwriting last 2 lines Paul Excel Programming 1 November 6th 04 08:11 PM
Exporting from multiple worksheets to single text file Chris Dunigan Excel Programming 3 September 16th 03 02:48 PM


All times are GMT +1. The time now is 06:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"