Consulting

Results 1 to 6 of 6

Thread: Working with a text file

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    Working with a text file

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That setsup the MAX and MIN values that you mentioned.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    what about the second question?

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Activeworkbook.Close
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •