Searching for a value in a TXT File

blelli

Board Regular
Joined
Jul 21, 2013
Messages
73
Dears,

How can I search for a value in a TXT file and return its correspondence in an Array?

In my Excel Spreadsheet, on cell A1, the user will type the airport code, like SBKP for example. It's always a 4 digit string.
Then, the VBA code will check if there is the airport SBKP into my TXT file, called airports.txt, if the airport was there, the VBA code will collect all information about this airport, otherwise the VBA code will return the message "INCORRECT AIRPORT" on cell A2.

The airports.txt file has the airports listed like - and I've about 3000 airports listed there:

A|SBKG|PRESIDENTE JOAO SUASSUNA|-7269167|-35895000|1646
R|15|147|5249|1|109100|147|-7265528|-35901833|1608|300|50
R|33|327|5249|0|0|0|-7273833|-35889972|1646|300|50


A|SBKP|VIRACOPOS INTL|-23006944|-47134444|2170
R|15|149|10630|1|110300|148|-22998467|-47147003|2139|300|51
R|33|329|10630|0|0|0|-23016372|-47121997|2170|300|50


A|SBLE|HORACIO DE MATTOS|-12482222|-41276944|1660
R|14|140|6831|0|0|0|-12482222|-41276944|1660|300|50
R|32|320|6831|0|0|0|-12482222|-41276944|1660|300|50

As you can see, the separator is "|", so when the airport is find, the VBA Code will have to collect all the following information:
A|SBKP|VIRACOPOS INTL|-23006944|-47134444|2170
R|15|149|10630|1|110300|148|-22998467|-47147003|2139|300|51
R|33|329|10630|0|0|0|-23016372|-47121997|2170|300|50

And store the first line it into an array called: Origin_Airport

Sometimes the number of Lines is bigger than 3, the first line corresponds to the airport line, the second, third, fourth and so on... corresponds to the number of runways available.

Can you help me guys?

Thank you so much
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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