473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Importing Text Files in Excel

Hi there,

I have a data in text files. I need to write some macros / vba to import into Excel . The text files is base on command syntax, as this format;

Command-X;
Data1 Data2 Data3
--------- --------- --------
valuex valueb valuec

Command Executed

So My macro's have to search the command-X, search a Data then collect the value.

So any idea, how can i start with, or sample macro?!


Thank you for your help
Jan 30 '07 #1
4 3935
Killer42
8,435 Expert 8TB
...So My macro's have to search the command-X, search a Data then collect the value.

So any idea, how can i start with, or sample macro?!
A good way to get started with this kind of thing is to tell Excel to record a new macro, then do the operation yourself. This generates the code for you. Then you can edit the macro and play with the code.
Jan 30 '07 #2
Hi killer

The problem is, the data is not the same order between the command syntax. So when imported it to excel, its difficult to arrange either using tab or delimeted.
But i will try to do per command syntax, which is have to extract manually first..
Jan 31 '07 #3
Killer42
8,435 Expert 8TB
The problem is, the data is not the same order between the command syntax. So when imported it to excel, its difficult to arrange either using tab or delimeted.
But i will try to do per command syntax, which is have to extract manually first..
Oh, so you mean your code needs to look at the command to decide what data to collect? Yes, that complicates things a bit.

Seems reasonably simple to do in VB, though. I'm sure we can come up with something. I'll get back to this at lunch time (in a few hours) and see if I can help.
Jan 31 '07 #4
Hi killer

The problem is, the data is not the same order between the command syntax. So when imported it to excel, its difficult to arrange either using tab or delimeted.
But i will try to do per command syntax, which is have to extract manually first..

Hello Moshin74!

I think you should just read your text file , find a key string and copy the corresponding value on your worksheet. Here is an example....

suppose your file \text.txt
contains the following text:

=============
Command-X;
---Data1 Data2 Data3
Data1 Data2 Data3
--------- --------- --------
valuex valueb valuec
Command Executed



Then you can try this vb code :

Private Sub CommandButton1_Click()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Dim i As Integer
Dim count, myLine ' string count,buffer for file reading
Dim Sfind 'string to find
i = 1
Sfind = "Data"

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("\text.txt", ForReading, TristateFalse)
myLine = " "
Do
myLine = f.Readline
MsgBox myLine, vbInformation ' show line buffer
count = InStr(1, myLine, Sfind, 1)
While count <> 0
Worksheets("MySheet").Cells(1, i) = Mid(myLine, count + Len(Sfind), 1)
count = InStr(count + Len(Sfind), myLine, Sfind, 1)
i = i + 1
Wend
Loop Until myLine = ""
f.Close

End Sub



It will search the keyword "Data" in your .txt, and it will store the following character in your worksheet ("MySheet") for each occurence (1,2,3,1,2,3) on the same line. If you add more details it can be improved !
Bye !
Jan 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
1
by: sparks | last post by:
I have never done this and wanted to ask people who have what is the best way. One person said import it to excel, then import it into access table. but since this will be done a lot, I am...
2
by: Mihael | last post by:
Need help when importing excel sheet with cca 8.000 records in a new table I get message subscript out of range. why?
7
by: mpdsal | last post by:
Hello. I have some very large text files that I need to import into Access. These files are basically SAP system reports that can be up to 100,000 records but they contain a boatload of data I...
3
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
5
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All...
28
by: kkadakia | last post by:
I get a daily excel file for a entire month which I want to transfer into Access at the end of the month. So, there are around 20-25 excel files I get by the end of the month, and I would like to...
3
by: scoots987 | last post by:
What do others do if you need to import excel files into SQL Server? My main problems are 1) zipcode formatting issues. If the column is a mix of zip and zip+4, I have problems retrieving all...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.