Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 186
Default REPOST: Please help with Output - Going across instead of down

I posted this a few days ago and havent had any replies. I assume that its
because maybe I wasnt clear enough. Hopefully I can explain what I am needing
the output to be.
I am using the following code to export cell selection to a txt file. The
code works fine, if I only select one column. However I run into problems
when I select multiple columns. Instead of the output being a1,b1,c1 a2,b2,c2
a3,b3,c3. I need the output to be a1,a2,a3 b1,b2,b3,c1,c2,c3 etc. depending
on number of columns selected.
Here is code I am currently using.
Sub Export2Textfile()
Dim Textfile As Variant
Dim LastRow As Long
Dim XportArea As Range
Dim Cel As Range
Dim iFnum As Integer
'Select a textfile to save to
Textfile = Application.GetSaveAsFilename( _
InitialFileName:="text.txt", _
FileFilter:="Text files, *.txt)", _
Title:="Save textfile as:")
If Textfile = False Then Exit Sub
On Error Resume Next
'Select the cells to export:
Set XportArea = Application.InputBox( _
"Select the cells to export:", _
"Use your mouse:", Selection.Address, Type:=8)
If XportArea Is Nothing Then Exit Sub
'open / create the textfile
iFnum = FreeFile
Open CStr(Textfile) For Output As iFnum
'loop cells
For Each Cel In XportArea
'write to textfile
Print #iFnum, Cel.Text
Next
Close #iFnum
End Sub

I am thinking I will need to add another loop. I just dont know how to get
it to go down instead of across. Any help would be greatly appreciated

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default REPOST: Please help with Output - Going across instead of down

Instead of:

For Each Cel In XportArea
'write to textfile
Print #iFnum, Cel.Text
Next

You could loop through the columns, then the rows of each column.

dim iCol as long
dim iRow as long

for icol = 1 to selection.columns.count
for irow = 1 to selection.rows.count
print #ifnum, selection.cells(irow,icol).text
next irow
next icol

Jack wrote:

I posted this a few days ago and havent had any replies. I assume that its
because maybe I wasnt clear enough. Hopefully I can explain what I am needing
the output to be.
I am using the following code to export cell selection to a txt file. The
code works fine, if I only select one column. However I run into problems
when I select multiple columns. Instead of the output being a1,b1,c1 a2,b2,c2
a3,b3,c3. I need the output to be a1,a2,a3 b1,b2,b3,c1,c2,c3 etc. depending
on number of columns selected.
Here is code I am currently using.
Sub Export2Textfile()
Dim Textfile As Variant
Dim LastRow As Long
Dim XportArea As Range
Dim Cel As Range
Dim iFnum As Integer
'Select a textfile to save to
Textfile = Application.GetSaveAsFilename( _
InitialFileName:="text.txt", _
FileFilter:="Text files, *.txt)", _
Title:="Save textfile as:")
If Textfile = False Then Exit Sub
On Error Resume Next
'Select the cells to export:
Set XportArea = Application.InputBox( _
"Select the cells to export:", _
"Use your mouse:", Selection.Address, Type:=8)
If XportArea Is Nothing Then Exit Sub
'open / create the textfile
iFnum = FreeFile
Open CStr(Textfile) For Output As iFnum
'loop cells
For Each Cel In XportArea
'write to textfile
Print #iFnum, Cel.Text
Next
Close #iFnum
End Sub

I am thinking I will need to add another loop. I just dont know how to get
it to go down instead of across. Any help would be greatly appreciated


--

Dave Peterson
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
Had to repost it!!! Prashant Excel Discussion (Misc queries) 1 April 23rd 10 03:19 PM
Repost for Ron Jenny B. Excel Discussion (Misc queries) 1 May 21st 08 09:39 AM
Repost Tim Excel Programming 11 July 28th 05 08:51 PM
Please repost ans to this one Mark \(InWales\)[_15_] Excel Programming 3 November 18th 04 07:00 PM
Getting output from an excel output back to cscript.. J S Excel Programming 0 January 21st 04 09:06 PM


All times are GMT +1. The time now is 07:31 AM.

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"