LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to generate txt files using Excel

Hello

May I please ask for your kind help?

Input.xls is an Excel file that has 3 worksheets. On
Sheet1 there are columns with data and formulas. All of
the values being calculated on this sheet, depend on 4
cells: A1, A2, A3, A4. Sheet 2 has many columns with
formulas. These formulas depend on the values that were
calculated on Sheet 1.

Sheet 3 has 4 columns and X rows. Each row profides a
combination of 4 parameters.

The steps that thus far I have been doing manually a

1. Open Sheet3, and copy the values in the 1st row.
2. paste the value from the 1st column [the value in cell
A1] of Sheet1 into A1 of Sheet 1

paste the value from the 2nd column [value in B1]of Sheet3
into cell A2 of Sheet 1

paste the value from the 3rd column[value in C1]of Sheet 3
into A3 of Sheet 1 of Sheet 1

paste the value from the 4th column [value inD1]of Sheet 3
into A4 of Sheet 1 of MainInput.xls

3. Wait for the values in both sheets 1 and 2
to be recalculated [This Input.xls file is a 40Mb file].

4. Go to Sheet 2 and Save it [only Sheet 2]
as Input1.txt [in some/any directory]. Save it as a Tab
delimited text file.

5. Repeat steps 1-4 for the values of the 2nd row of
Sheet3.

Keep repeating steps 1-4 until we run out of rows on Sheet3

Thus, if Sheet 3 has X rows, then the output of this macro
would be X tab delimited files named Input1.txt,
Input2.txt, ..., InputX.txt

Any help or suggestion would be greatly appreciated.

===========================
An example of what I am trying to do:

This example is for the case when we have
text below on Sheet 3

1 2 3 4
5 6 7 8
9 10 11 12

Thus, if the second row of Sheet3 is
5 6 7 8
we create Input2.txt which is identical to
how Sheet2 looks when in Sheet1 we have
cell A1=5, cell A2=6, A3=7, A4=8

I need to generate thousands of these input?.txt
files. I simply can't do this manually.
I would truly appreciate any help with this problem.

Sincerely


Frank

P.S.
When I clicked on Macro/Record New Macro,
the output that I got is:

Sub Macro2()

Sheets("Sheet3").Select
Selection.Copy
Sheets("Sheet1").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("B1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("C1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("D1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Sheet2").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs
Filename:="C:\source\Input1.txt", FileFormat:= _
xlText, CreateBackup:=False
Sheets("Sheet3").Select
Range("A2").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("C2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("D2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Input1").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs
Filename:="C:\source\Input2.txt", FileFormat:= _
xlText, CreateBackup:=False
Sheets("Sheet3").Select
Range("A3").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("B3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A2").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("C3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A3").Select
ActiveSheet.Paste
Sheets("Sheet3").Select
Range("D3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet1").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Input2").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs
Filename:="C:\source\Input3.txt", FileFormat:= _
xlText, CreateBackup:=False
End Sub
 
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
macro to generate next number puiuluipui Excel Discussion (Misc queries) 7 March 17th 21 05:15 AM
How to create a macro in excel so that it can generate a list ofunique records using all permutations and combinations of the data in eachrow ad column Rizwan[_4_] Excel Discussion (Misc queries) 1 August 6th 09 01:44 PM
How to generate a text file from Excel using a macro or script? Frank Excel Discussion (Misc queries) 1 January 6th 08 05:11 PM
How to generate a text file from Excel using a macro or script? Frank Excel Discussion (Misc queries) 0 January 6th 08 05:11 PM
Macro to generate a file from another Dileep Chandran Excel Worksheet Functions 10 December 4th 06 02:52 PM


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