+ Reply to Thread
Results 1 to 5 of 5

Input data from file to Excel in Column Format

  1. #1
    Registered User
    Join Date
    11-04-2005
    Posts
    3

    Input data from file to Excel in Column Format

    Hey everyone I'm new to VB and need some help.

    I'm trying to input a file from a .dat file (output from Fortran code). The .dat file contains multiple column such as:
    ---------
    2 5.48564954E+05 4.07889292E+06 5.47506020E+05 4.07922513E+06
    3 5.48560812E+05 4.07880932E+06 5.47497497E+05 4.07914291E+06
    4 5.48556669E+05 4.07872573E+06 5.47488975E+05 4.07906069E+06
    5 5.48552526E+05 4.07864214E+06 5.47480453E+05 4.07897847E+06
    6 5.48548383E+05 4.07855855E+06 5.47471931E+05 4.07889625E+06
    7 5.48544240E+05 4.07847495E+06 5.47463408E+05 4.07881404E+06
    8 5.48540097E+05 4.07839136E+06 5.47454886E+05 4.07873182E+06
    9 5.48535954E+05 4.07830777E+06 5.47446364E+05 4.07864960E+06
    10 5.48531811E+05 4.07822417E+06 5.47437842E+05 4.07856738E+06
    .
    .
    .
    ---------

    I want to open the .dat file and input this data into column format in my excel sheet.

    Could someone tell me how this is done, I would greatly appreciate it.

    Nuc

  2. #2
    Tom Ogilvy
    Guest

    Re: Input data from file to Excel in Column Format

    Turn on the macro Recorder

    Tools=>Macros=>Record a Macro

    then open the file manually and go through the Text import wizard.

    turn off the macro recorder.

    You might have to rename the file to have a .txt extension to do it
    manually, but I think it will work without that.

    Now look at the recorded code.

    Alter to suit your needs.

    See help on the OpenText method.

    --
    Regards,
    Tom Ogilvy


    "Nuc" <[email protected]> wrote in message
    news:[email protected]...
    >
    > Hey everyone I'm new to VB and need some help.
    >
    > I'm trying to input a file from a .dat file (output from Fortran code).
    > The .dat file contains multiple column such as:
    > ---------
    > 2 5.48564954E+05 4.07889292E+06 5.47506020E+05 4.07922513E+06
    > 3 5.48560812E+05 4.07880932E+06 5.47497497E+05 4.07914291E+06
    > 4 5.48556669E+05 4.07872573E+06 5.47488975E+05 4.07906069E+06
    > 5 5.48552526E+05 4.07864214E+06 5.47480453E+05 4.07897847E+06
    > 6 5.48548383E+05 4.07855855E+06 5.47471931E+05 4.07889625E+06
    > 7 5.48544240E+05 4.07847495E+06 5.47463408E+05 4.07881404E+06
    > 8 5.48540097E+05 4.07839136E+06 5.47454886E+05 4.07873182E+06
    > 9 5.48535954E+05 4.07830777E+06 5.47446364E+05 4.07864960E+06
    > 10 5.48531811E+05 4.07822417E+06 5.47437842E+05 4.07856738E+06




  3. #3
    Registered User
    Join Date
    11-04-2005
    Posts
    3

    What about?

    What about using an open statement such as:

    'Open "file.dat" For Input As #1 'Open file for input to worksheet
    'For i = 1 To ??
    'Line Input #1, commandline
    'Worksheets("Sheet2").Cells(i, 1) = commandline

    I don't really know how to go from here.. This is only inputing the file into one column and I need two or more columns.

    Using the record macro like you said is ok but this would seem to work so that I can define the starting and stopping point at where I need to take the data. Such as taking lines 13 to 100 from the .dat file and importing them to the worksheet.

    Thanks,

    Nuc

  4. #4
    Tom Ogilvy
    Guest

    Re: Input data from file to Excel in Column Format

    See Chip Pearson's site for sample code. Specify space as a delimiter:

    http://www.cpearson.com/excel/imptext.htm import/export text files

    --
    Regards,
    Tom Ogilvy


    "Nuc" <[email protected]> wrote in message
    news:[email protected]...
    >
    > What about using an open statement such as:
    >
    > 'Open "file.dat" For Input As #1 'Open file for input to worksheet
    > 'For i = 1 To ??
    > 'Line Input #1, commandline
    > 'Worksheets("Sheet2").Cells(i, 1) = commandline
    >
    > I don't really know how to go from here.. This is only inputing the
    > file into one column and I need two or more columns.
    >
    > Using the record macro like you said is ok but this would seem to work
    > so that I can define the starting and stopping point at where I need to
    > take the data. Such as taking lines 13 to 100 from the .dat file and
    > importing them to the worksheet.
    >
    > Thanks,
    >
    > Nuc
    >
    >
    > --
    > Nuc
    > ------------------------------------------------------------------------
    > Nuc's Profile:

    http://www.excelforum.com/member.php...o&userid=28572
    > View this thread: http://www.excelforum.com/showthread...hreadid=482329
    >




  5. #5
    Registered User
    Join Date
    11-04-2005
    Posts
    3

    Thanks Tom

    Thanks for the info I will try and get this going.

    Nuc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1