VBA to extract data from a .txt file

nevillestoke

Active Member
Joined
Mar 6, 2002
Messages
252
I have looked through the site but can't find anything quite like this - I know a little VBA, but this seems to be more than I imagined. I have a .txt file that changes monthly in one column - the Gross Pay - and I would like to extract the Gross Pay from the .txt file (let's say the file is named "2011monthly.txt") based on the code which may be one, two or three characters and is "joined" to the name. I am comfortable enough with the Vlookup function, but not when extracting from a text file. Also, the list of names is quite stable with only an occasional addition or deletion.

I am using Excel 2003 on Windows XP Professional and an example of how the data is presented is given below.

11-02-22 2011XYZ Company
03:07 123 Any Street
Toronto, ON

CURRENT MONTH

Period/Year: 05/11 to 08/11
Employees: ALL
Departments: ALL
StatusTypes: ALL
Pay Types: ALL

Code Name Dept Gross Pay
------------------------------- ---------------
1 Doe, John PLANT 1500
2 Public, Jane P. PLANT 1650
55 Jones, J.J. DRIVER 2150
75 Smith, Kevin PLANT 1350
102 Simpson, Homer Office 1158.66
175 Ball, Lucille Office 1291.6

I would appreciate any help you can offer and can provided additional information if needed.

Thanks, Neville.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
HI Neville,

As a rough fix, why not import the lot into a temp Sheet then copy the column that you need from it?

(or even set the import to just get the Gross PAy column;

With NewSht.QueryTables.Add( _
Connection:="TEXT;" & FILENAME _
, Destination:=NewSht.Range("$A$1"))
blah blah other settings

.TextFileColumnDataTypes = Array(9, 9, 9, 1,)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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