Copy specific lines from multiple text files into excel

aqeel

New Member
Joined
Apr 23, 2015
Messages
6
Hey,

I have multiple text files in a folder containing analysis results of samples..

where the second line represent (number of the sample) and 12th line represents (results of analysis)

The text file looks like this:

1st line: text
2nd line: text
....
12th line: text text text

I want to copy second and 12th line into 1 row of 4 cells in an excel sheet... all copied data are in numbers
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,​
what is the end of line character(s) sequence ?​
Or better just link some text files and the expected result workbook on a files host website like Dropbox …​
 
Upvote 0
Hi,​
what is the end of line character(s) sequence ?​
Or better just link some text files and the expected result workbook on a files host website like Dropbox …​
Hey thanks for replying..

here's the a sample file

and this is what I want to copy, and how to have them on excel (pics attached)

per in mind.. I have multiple text files in a folder all having the same structure, and I want to copy all into excel

Thanks in advance
 

Attachments

  • 12.png
    12.png
    19 KB · Views: 24
  • 13.png
    13.png
    2.2 KB · Views: 24
Upvote 0
According to your attachment a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
    Dim P$, T$, F%, R&, S$()
        P = ThisWorkbook.Path & "\"
        T = Dir$(P & "*.txt"):  If T = "" Then Beep: Exit Sub
        F = FreeFile
        R = 1
        [A1].CurrentRegion.Offset(1).Clear
        Application.ScreenUpdating = False
    Do
        Open P & T For Input As #F
        S = Split(Input(LOF(F), #F), vbCrLf)
        Close #F
        R = R + 1
        Cells(R, 1).Resize(, 4).Value2 = Evaluate("{" & S(1) & "," & Replace(S(11), vbTab, ",") & "}")
        T = Dir$
    Loop Until T = ""
        Application.ScreenUpdating = True
End Sub
 
Upvote 0
According to your attachment a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
    Dim P$, T$, F%, R&, S$()
        P = ThisWorkbook.Path & "\"
        T = Dir$(P & "*.txt"):  If T = "" Then Beep: Exit Sub
        F = FreeFile
        R = 1
        [A1].CurrentRegion.Offset(1).Clear
        Application.ScreenUpdating = False
    Do
        Open P & T For Input As #F
        S = Split(Input(LOF(F), #F), vbCrLf)
        Close #F
        R = R + 1
        Cells(R, 1).Resize(, 4).Value2 = Evaluate("{" & S(1) & "," & Replace(S(11), vbTab, ",") & "}")
        T = Dir$
    Loop Until T = ""
        Application.ScreenUpdating = True
End Sub
Hey,
sorry, didn't get the notification for your reply
does this code pull the data from multiple txt files in a single folder?
because I don't think so..
 
Upvote 0

Yes as you can see within this demonstration and just trying it obviously before asking …​
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,424
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top