Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: AlwaysWillingToLearn
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 yOk 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") = Crange("B1") = X
range("B2") = X2
range("B3") = X3Im 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.

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()

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,

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.

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,

![]() |
set command and xcopy
|
Free Pascal & Hardware po...
|

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