Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to output a textfile format in such design

Hi all,

I'm new for doing Excel programming.
Can someone teach me how to output a text file which the output design
should be like this:

Fruit01072008
Apple
classA;5000
classB;6000
classC;7000
Orange
classA;1000
classB;3000
classC;5000
Strawberry
ClassA;850
ClassB;1000
classC;1299


In the Excel Sheet contain:

Column A Column B Column C Column D
Fruit Orange 1000 ClassA
Fruit Orange 3000 ClassB
Fruit Orange 5000 ClassC
Fruit Apple 5000 ClassA
Fruit Apple 6000 ClassB
Fruit Apple 7000 ClassC
Fruit Strawberry 850 ClassA
Fruit Strawberry 1000 ClassB
Fruit Strawberry 1299 ClassC

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default How to output a textfile format in such design

Put your data in A1 thru A13 and then run:

Sub Macro1()
ChDir "C:\"
ActiveWorkbook.SaveAs Filename:="C:\Book1.txt", FileFormat:=xlText, _
CreateBackup:=False
End Sub

--
Gary''s Student - gsnu2007j


" wrote:

Hi all,

I'm new for doing Excel programming.
Can someone teach me how to output a text file which the output design
should be like this:

Fruit01072008
Apple
classA;5000
classB;6000
classC;7000
Orange
classA;1000
classB;3000
classC;5000
Strawberry
ClassA;850
ClassB;1000
classC;1299


In the Excel Sheet contain:

Column A Column B Column C Column D
Fruit Orange 1000 ClassA
Fruit Orange 3000 ClassB
Fruit Orange 5000 ClassC
Fruit Apple 5000 ClassA
Fruit Apple 6000 ClassB
Fruit Apple 7000 ClassC
Fruit Strawberry 850 ClassA
Fruit Strawberry 1000 ClassB
Fruit Strawberry 1299 ClassC


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to output a textfile format in such design

This code will give you exactly what you posted

Sub SaveData()

Const ForReading = 1, ForWriting = 2, _
ForAppending = 3

fileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If fileSaveName = False Then
MsgBox ("Cannot Save File")
Exit Sub
End If

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile(fileSaveName, True)

OutputLine = "Fruit" & Format(Date, "MMDDYYYY")
f.writeline OutputLine

Fruit = ""
RowCount = 1
Do While Range("A" & RowCount) < ""
If Range("B" & RowCount) < Fruit Then
Fruit = Range("B" & RowCount)
f.writeline Fruit
End If

f.writeline Range("D" & RowCount) & ";" & Range("C" & RowCount)

RowCount = RowCount + 1
Loop
f.Close


End Sub


" wrote:

Hi all,

I'm new for doing Excel programming.
Can someone teach me how to output a text file which the output design
should be like this:

Fruit01072008
Apple
classA;5000
classB;6000
classC;7000
Orange
classA;1000
classB;3000
classC;5000
Strawberry
ClassA;850
ClassB;1000
classC;1299


In the Excel Sheet contain:

Column A Column B Column C Column D
Fruit Orange 1000 ClassA
Fruit Orange 3000 ClassB
Fruit Orange 5000 ClassC
Fruit Apple 5000 ClassA
Fruit Apple 6000 ClassB
Fruit Apple 7000 ClassC
Fruit Strawberry 850 ClassA
Fruit Strawberry 1000 ClassB
Fruit Strawberry 1299 ClassC


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
Combo chart format- what is the best way to achieve this design? ker_01 Charts and Charting in Excel 1 March 9th 09 11:18 PM
How to format userform label at design time? Denis[_4_] Excel Programming 2 July 1st 06 10:01 PM
report output format Tim3057[_3_] Excel Programming 1 January 16th 06 03:00 PM
Web Query output, how to format? kinmorr Excel Programming 0 June 13th 05 07:10 PM
Hyperlinks Inserted in Design Mode inactive once Exited Design Mod Craig Excel Programming 0 March 16th 05 04:53 PM


All times are GMT +1. The time now is 08:42 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"