Hello!
I'm newby to ms excel vba.
I want to read text files where are in a folder and the data of each file to transfer in a workbook/sheet as list.
The text files there are to C:tst.
The data of every text file has the following view:
UserName
XXXXXXXXXXXXXX
PC Name
YYYYYYYYYYYYYY
SerialNumber
ZZZZZZZZZZZZZZZ
and i want to view them to excel as:
Column 1 Column 2 Column 3
UserName PC Name SerialNumber
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
XXXXXXXXXXX YYYYYYYYYYY ZZZZZZZZZZZZZ
etc.
The only that I've done is the following, but, i receive to excel sheet, only the data of one text file at a time:
Sub ImportFromText()
Dim c As Integer, data As String
Cells.ClearContents
Open "C:tstFileName.txt" For Input As #1
c = 0
Do Until EOF(1)
Line Input #1, data
Worksheets("Sheet1").Range("A1").Offset(0, c) = data
c = c + 1
Loop
Close #1
End Sub
and the result:
ώUserName XXXXXXXXXXXXXX PC Name YYYYYYYYYYYYYY SerialNumber ZZZZZZZZZZZZZZZ
Could anybody help me please?
Thanks
Sotiris
Hi Sotiris
You can give this a try.
Hope this helps.
Sunny
Hi Sunny!
Thank you very much for your help.
This is exactly the format that I want.
The next step that I want is the "macro" to read all the files from the folder and not only one as does now. I think that must add a variable that read every file of the folder and write the data as you have make the code. Imagine that the folder has 300 files. That was my aknowlegde problem with the programming.
Is something that you can help me?
Thank you for another time.
Give this a try.
Good luck
Sunny
Hi Sunny.
I tried your new file, was o.k but i added something (as you 'll see) which complete the code and correct more good its viewing.
I hope that you 'll agree.
Thank you very much.
Sotiris.
Hi Sotiris
Glad it is working for you.
To add on to your codes, just move the line
Application.ScreenUpdating = True
To the bottom of your code (just before the End Sub)
It will improve the speed tremendously.
Sunny
Many Thanks!
Hello
In the code provided I see that using Select is unnecessary so instead of these three lines
Application.CutCopyMode = False
Selection.Delete
You can use directly
Excellent! Thanks for the code SunnyKow!
Hi Morgan
You are welcome .
Sunny