PDA

View Full Version : Working with a text file



oleg_v
07-17-2010, 10:24 PM
Hi

I need some help with a macro:

i attached a text file with a data,
what i need is that excel will open the file calculate the maximum number ,
minimum number after that delete all the data from the text file and paste those two numbers then save the file close it and close excel.


thanks

Oleg

Bob Phillips
07-18-2010, 02:47 AM
Workbooks.OpenText Filename:="C:\data.txt", Origin:=xlMSDOS, StartRow:=1, _
DataType:=xlDelimited, _
ConsecutiveDelimiter:=False, Tab:=True, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Range("B1").FormulaR1C1 = "=MAX(C[-1])"
Range("B2").FormulaR1C1 = "=MIN(C[-1])"
Range("B1:B2").Copy
Range("B1:B2").PasteSpecial Paste:=xlPasteValues
Columns(1).Delete
Application.CutCopyMode = False
ActiveWorkbook.Save

oleg_v
07-18-2010, 03:18 AM
thanks for your replay
i wanted to ask a couple of questions about your code:\

1) what does those lines mean :
Range("B1").FormulaR1C1 = "=MAX(C[-1])"
Range("B2").FormulaR1C1 = "=MIN(C[-1])"

2)the macro open a new work book how can i get that all work books will close at the end


thnaks

Bob Phillips
07-18-2010, 04:03 AM
That setsup the MAX and MIN values that you mentioned.

oleg_v
07-18-2010, 10:27 PM
what about the second question?

Bob Phillips
07-19-2010, 12:32 AM
Activeworkbook.Close