• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Transfer data from text files as list in a worksheet|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Transfer data from text files as list in a worksheet|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosTransfer data from text files as li…
sp_PrintTopic sp_TopicIcon
Transfer data from text files as list in a worksheet
Avatar
Sotiris Degiorgio
Greece, Athens

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 13, 2013
sp_UserOfflineSmall Offline
1
July 7, 2017 - 6:01 pm
sp_Permalink sp_Print

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:\tst\FileName.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

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
July 8, 2017 - 11:23 am
sp_Permalink sp_Print

Hi Sotiris

You can give this a try.

Hope this helps.

Sunny

Avatar
Sotiris Degiorgio
Greece, Athens

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 13, 2013
sp_UserOfflineSmall Offline
3
July 10, 2017 - 4:35 pm
sp_Permalink sp_Print

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.

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
4
July 10, 2017 - 6:01 pm
sp_Permalink sp_Print

Give this a try.

Good luck

Sunny

Avatar
Sotiris Degiorgio
Greece, Athens

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 13, 2013
sp_UserOfflineSmall Offline
5
July 10, 2017 - 11:14 pm
sp_Permalink sp_Print

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.

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
6
July 11, 2017 - 9:09 am
sp_Permalink sp_Print

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

Avatar
Sotiris Degiorgio
Greece, Athens

Active Member
Members
Level 0
Forum Posts: 4
Member Since:
February 13, 2013
sp_UserOfflineSmall Offline
7
July 11, 2017 - 10:33 pm
sp_Permalink sp_Print

Many Thanks!

Avatar
YasserKhalil
Member
Members
Level 0
Forum Posts: 13
Member Since:
June 30, 2016
sp_UserOfflineSmall Offline
8
August 4, 2017 - 6:11 am
sp_Permalink sp_Print sp_EditHistory

Hello

In the code provided I see that using Select is unnecessary so instead of these three lines

Rows(delRow).Select
Application.CutCopyMode = False
Selection.Delete

You can use directly

Rows(delRow).Delete
Avatar
morgan1974

New Member
Members
Level 0
Forum Posts: 1
Member Since:
August 16, 2017
sp_UserOfflineSmall Offline
9
August 16, 2017 - 5:09 pm
sp_Permalink sp_Print sp_EditHistory

Excellent! Thanks for the code SunnyKow!

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
10
August 16, 2017 - 6:15 pm
sp_Permalink sp_Print

Hi Morgan

You are welcome Smile.

Sunny

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Barbara Murray
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
Hans Hallebeek: 185
Newest Members:
Kwaje Alfred Mogga
thong nguyen
Appiagyei Kofi Frimpong
Hilary Burchfield
Richie Wright
Adel Kock
Barbara Murray
Doug Milne
Siobhan Stringer
Rob Rooth
Forum Stats:
Groups: 3
Forums: 24
Topics: 6542
Posts: 28648

 

Member Stats:
Guest Posters: 49
Members: 32831
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.