VBA: open and copy data from multiple (txt. files) to excel

CRG

New Member
Joined
Nov 7, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
hi, need macro to open and copy data from multiple txt. files (exactly i need direct 35 values(years)) to excel. I did macro for one year, but im struggling to do it for 35 years, can someone help me with solution please?
VBA Code:
Sub txt_to_excel()

Dim X As Double
Dim TXT As String

' Adresss
Open "C:\Users\ppXXXX\Desktop\Country\file\00001\areas\year.txt" For Input As #1

X = 0
    Do While Not EOF(1)
    Line Input #1, TXT
    Cells(1, 1).Offset(X, 0) = TXT
    X = X + 1
    Loop

Close #1

End Sub


Thanks Crg.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi CRG. You need to provide the folder location for the text files. Basically loop through all text files in the folder and perform the same operation. You also need to indicate where all of the new data goes. If it's just in the next column, then you can simply add 1 to the cells column location after each file is processed. HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,976
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top