Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Export each column in a different txt file

Catherine,

Try code like the following. Change the lines marked with <<< to the
appropriate values. WS is the worksheet name. FirstCol is the column
number of the first column of data to be exported. LastCol is the
column number of the last column of data to be exported. You don't
specify how you want the text files to be named. The code creates a
file name called "File_N.txt" where N is the column number. The files
are created in the same directory as the workbook resides.

Sub AAA()
Dim R As Range
Dim FirstCol As Long
Dim LastCol As Long
Dim FirstRow As Long
Dim FName As String
Dim FNum As Integer
Dim WS As Worksheet

FirstCol = 1 '<<< CHANGE
LastCol = 3 '<<< CHANGE
FirstRow = 1 '<<< CHANGE
Set WS = Worksheets("Sheet1") '<<< CHANGE
Set R = WS.Cells(FirstRow, FirstCol)
Do Until R.Column LastCol
FNum = FreeFile
FName = ThisWorkbook.Path & "\" & _
"File_" & CStr(R.Column) & ".txt" '<<<< Filename??
Open FName For Output Access Write As #FNum
Do Until R.Text = vbNullString
Print #FNum, R.Text
Set R = R(2, 1)
Loop
Close #FNum
Set R = WS.Cells(FirstRow, R.Column + 1)
Loop

End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 17 Feb 2009 13:24:05 -0800, Catherine
wrote:

Hi,

I need to create a separate txt file for each column in my worksheet.

Do you know how to do it?

Thanks

Catherine

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
export re-order input fields to export file [csv] madisonpete Excel Worksheet Functions 0 November 30th 07 03:51 PM
need to export row as csv file with column e plus .bom as file name rod Excel Discussion (Misc queries) 5 November 2nd 06 03:38 AM
Export excel file to semicolon delimited text file capitan Excel Discussion (Misc queries) 5 April 7th 05 03:06 AM
How do I import text file, analyze data, export results, open next file Geoffro Excel Programming 2 March 6th 05 08:02 PM
I need to export to text file a column mark Excel Programming 2 September 9th 04 01:57 PM


All times are GMT +1. The time now is 09:06 PM.

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

About Us

"It's about Microsoft Excel"