Computing.Net > Forums > Programming > VBA Read text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA Read text file

Reply to Message Icon

Name: AlwaysWillingToLearn
Date: October 7, 2008 at 07:01:39 Pacific
OS: Winxp pro sp3
CPU/Ram: 3.0
Product: Gigabyte
Comment:

Hi All,

Ok i have a text file (notepad) which contains data in a particular as bellow

NAME AGE HEIGHT DOB WEIGHT
b 22 22 x y
A 13 23 x2 y
c 44 44 x3 y

Ok so, in VBA (Excel) how can i just get the data from NAME and DOB? considering there are spaces there are no columns as such like in Excel.

So in sheet1

range("A1") = B
range("A2") = A
range("A3") = C

range("B1") = X
range("B2") = X2
range("B3") = X3

Im a bit lost, any help will be appreciated.

Thanks,


Sorry the formatting messes up when i post, the NAME, AGE, HEIGHT are titles sepeated by spaces, and the data appares underneath them.



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 7, 2008 at 17:34:10 Pacific
Reply:

I'd normally tell you to look at Application.Workbooks.OpenText(), but it'd probably just be easier to record a macro of you opening the input file, and take that .OpenText()


0

Response Number 2
Name: AlwaysWillingToLearn
Date: October 8, 2008 at 01:33:06 Pacific
Reply:

Hi Razor_2.3,

Thanks for your reply, however i dnot actually want ALL the text in the file, just certain parts, i have come up with a solution which isnt quite ready yet, but im having fun fixing it. I no doubt will run into problems later so will post back.

The thing i need to do now i query the text file to file certain values according to given text, for example, if someone wants to know the names of people who are all 22 years old, i will need to parse the document and get the names, i can do this, it works, just a bit slow though.

Thanks,


0

Response Number 3
Name: Razor2.3
Date: October 8, 2008 at 04:15:32 Pacific
Reply:

Yes, but if you open it up as a Workbook, you don't have to worry about the logic behind the text parsing. Then, when you're done, just close it. If you're insistent on not doing it the fast and easy way, then read the line in and use Mid() and Trim() to parse out the values you care about.


0

Response Number 4
Name: AlwaysWillingToLearn
Date: October 14, 2008 at 01:17:56 Pacific
Reply:

Hey Razor,

I understand what you are suggetsing, thing is the file is over 6mb and when copy pasting into Excel, it says there are more lines than space on the worksheet.

Iv figured out a way of getting the info i want, what i essentially wanted was to get all the figures in the 3rd column and put them into column A in Excel, but remove any repitition. It works great.

But the advise you gave, did make sense and was proberbly the most sensible way of approaching it so thank you very much for helping me.

Thanks,


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


set command and xcopy Free Pascal & Hardware po...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBA Read text file

read text file in c to char pointer www.computing.net/answers/programming/read-text-file-in-c-to-char-pointer/7074.html

How To Read/Write File in VB6 www.computing.net/answers/programming/how-to-readwrite-file-in-vb6/7105.html

Reading from a text file in C++ www.computing.net/answers/programming/reading-from-a-text-file-in-c/8983.html