I need to output several "sections" into one txt file and am confused how to do it.
Here is what I am needing:
Sheet4: a1-a166
Sheet2: Entire A column - this could vary. I dont know how to determine last row
Sheet3: Column count varys - I have a variable in sheet1(Sheet1!E2) x 5 rows. Output should be b1,b2,b3,b4,b5. c1,c2,c3,c4,c5 etc depending on variable
Sheet 4 a:626-a656
Can I use a varible to save text as Sheet1!D2.txt
I am currently using the following code. However I have to go in and select cells.
Any help would be greatly appreciated.[/code]
Here is what I am needing:
Sheet4: a1-a166
Sheet2: Entire A column - this could vary. I dont know how to determine last row
Sheet3: Column count varys - I have a variable in sheet1(Sheet1!E2) x 5 rows. Output should be b1,b2,b3,b4,b5. c1,c2,c3,c4,c5 etc depending on variable
Sheet 4 a:626-a656
Can I use a varible to save text as Sheet1!D2.txt
I am currently using the following code. However I have to go in and select cells.
Code:
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 Append As iFnum
'loop cells
For Each Cel In XportArea
'write to textfile
Print #iFnum, Cel.Text
Next
Close #iFnum
End Sub
Any help would be greatly appreciated.[/code]