Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to insert values from a file and save another sheet as a .txt file

Hello All,

Thanks in advance for reading.

I have two input files: MainInput.xls and ParCombos.txt.

ParCombos.txt is a tab delimited text file that has 4 columns.
Each row in this document contains a combination of 4 parameters.

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

I desperately need to write a macro to do the steps below, but I
don't know where to start. The steps a

1. Open ParCombos.txt, and copy the values in the 1st row.
2. paste the value from the 1st column of ParCombos.txt
into A1 of Sheet 1 of MainInput.xls

paste the value from the 2nd column of ParCombos.txt
into A2 of Sheet 1 of MainInput.xls

paste the value from the 3rd column of ParCombos.txt
into A3 of Sheet 1 of MainInput.xls

paste the value from the 4th column of ParCombos.txt
into A4 of Sheet 1 of MainInput.xls

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

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

5. Repeat steps 1-5 for the values of the 2nd row of ParCombos.txt.
Keep repeating steps 1-5 until we run out of rows in ParCombos.txt

Thus, if ParCombos.txt has X rows, then the output of this macro would
be X tab delimited files named Maininput1.txt, MainInput2.txt, ...,
MainInputx.txt

Any help would be appreciated.

Many Thanks


Frank

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to insert values from a file and save another sheet as a .txt file

Hello Trevor

Thank you very much for your suggestion!
I apologize for not realizing that I should do this
earlier.

And then you might need to come back to the group for

some more advice ...
but you'll have some code to refine rather than everyone

second guessing and
starting from scratch.


I had recorded the following macro when I had the 4
columns of parameters data [each row gives a different
combination of parameters] on Sheet 3.

The combination of parameters that I had on Sheet 3 is

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

This tells us that the second combination of parameters is
5, 6, 7, 8.

The macro 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\MainInput1.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("MainInput1").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs
Filename:="C:\source\MainInput2.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("MainInput2").Select
Application.CutCopyMode = False
ActiveWorkbook.SaveAs
Filename:="C:\source\MainInput3.txt", FileFormat:= _
xlText, CreateBackup:=False
End Sub


I need to generate hundreds of these maininput.txt
files. I would truly appreciate any help with this
problem.

Sincerely


Frank



Hello All,

Thanks in advance for reading.

I have two input files: MainInput.xls and

ParCombos.txt.

ParCombos.txt is a tab delimited text file that has 4

columns.
Each row in this document contains a combination of 4

parameters.

MainInput.xls is an Excel file that has 2 worksheets.

On the first
sheet there are many columns with data and formulas.

All of the
values being calculated on this sheet, depend on 4

cells:
A1, A2, A3, A4. The second sheet has many columns with

formulas.
These formulas depend on the values that were

calculated on Sheet 1.

I desperately need to write a macro to do the steps

below, but I
don't know where to start. The steps a

1. Open ParCombos.txt, and copy the values in the 1st

row.
2. paste the value from the 1st column of ParCombos.txt
into A1 of Sheet 1 of MainInput.xls

paste the value from the 2nd column of ParCombos.txt
into A2 of Sheet 1 of MainInput.xls

paste the value from the 3rd column of ParCombos.txt
into A3 of Sheet 1 of MainInput.xls

paste the value from the 4th column of ParCombos.txt
into A4 of Sheet 1 of MainInput.xls

3. Wait for the values in both sheets 1 and 2 in

Maininput.xls
to be recalculated [This MainInput.txt file is a

40Mb file].

4. Go to Sheet 2 of Maininput.xls and Save it [only

Sheet 2]
as Maininput1.txt [in some/any directory]. Save it as

a Tab delimited
text file.

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

ParCombos.txt.
Keep repeating steps 1-5 until we run out of rows

in ParCombos.txt

Thus, if ParCombos.txt has X rows, then the output of

this macro would
be X tab delimited files named Maininput1.txt,

MainInput2.txt, ...,
MainInputx.txt

Any help would be appreciated.

Many Thanks


Frank



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to insert values from a file and save another sheet as a .txt file

P.S.

Thus we save MainInput2.txt, which consists of
how Sheet2 looks when in Sheet1 we have
cell A1=5, cell A2=6, A3=7, A4=8

The combination of parameters that I had on Sheet 3 is

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

This tells us that the second combination of parameters is
5, 6, 7, 8.

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
2007 Macro to Open File, Delete Contents, Save New File Flintstone[_2_] Excel Discussion (Misc queries) 2 February 1st 10 11:25 PM
Can you save 1 sheet from a large file into another file? imktew Excel Worksheet Functions 2 January 17th 08 05:46 AM
how do I get a macro to save a sheet and set the file name? MadasMax Excel Discussion (Misc queries) 1 September 16th 07 12:04 PM
copy the same raws of all sheets from about a 100 file to a new sheet of a book and save the file [email protected] Setting up and Configuration of Excel 0 March 14th 07 02:13 AM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


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

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"