Importing a Portion of a .txt file by pattern - Please Help

Jeremy42

New Member
Joined
Apr 16, 2015
Messages
3
I am having trouble setting up the pattern recognition part of the macro for importing part of a .txt file. The part of the file I want imported looks like

There is more to the file above this with varying row #'s - meaning no fixed rows #'s or pattern

Component,Heading1,Heading2,Heading 3, Heading 4,Heading5
1, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
2, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
3, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
4, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
5, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
6, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
7, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11
8, 0.100E+11, 0.000E+00, 0.100E+11, 0.100E+11

There is more to the file below this with varying row #'s - meaning no fixed row #'s or pattern

What I need is to be able to do is essentially copy the part that starts with Component and then include all the lines below it up to a textbox defined value +1 eg:
D = Val(SimulationsTextBox.Text) +1 (the simulations text box will always be different so I need to have this variable as part of the pattern recognition and this is already defined elsewhere)
and in the above example the simulations text box value is 8 so it copies 9 lines total starting with Component

Unfortunately this value will always change and I cannot use the standard import file, plus the file is very large so I cannot copy all the file starting with Component then delete the rows I do not need- I just need those 9 lines in this example.

I already know how to open the file and/or read it. I am just looking for the code for the pattern that lets me highlight the desired section and import them into cell A1 of sheet 2 in the already open excel file.

Please describe what each line of code does because I am a beginner at VB and Excel Macro coding.

Once that selection is imported into excel I would like to split it up into separate cells using comma delineated method.

Due to large file size, listing the fastest way for VB to execute this would be greatly appreciated.

Thanks,
Jeremy
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,203,203
Messages
6,054,099
Members
444,702
Latest member
patrickmg17

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