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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,867
Messages
6,175,074
Members
452,611
Latest member
bls2024

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