Importing .txt file into vba

Bart196

New Member
Joined
Dec 11, 2017
Messages
8
I tried searching for answer for a couple days, cannot find one. Maybe you guys can help.

I am trying to load data from an .txt file, split the columns, and paste the data into excel using vba. I managed piece together a macro, but pasting the data line by line is very slow. How can I speed up this process?

*Only the relevant code is posted below

Bonus points if you can delete the first row in the loaded .txt file.

Dim MyData As String

FilePath = *Folder Location*

Open FilePath For Binary As #1
MyData = Space$(LOF(1))
Get #1 , , MyData
Close #1

i=1
For Each Row In VBA.Split(MyData, vbCrLf)
j = 1
Selection.Offset(1, 0).Select


For Each col In VBA.Split(Row, vbTab)

ActiveCell.Offset(i - 1, j - 1).Value = col
j = j + 1​

Next col​

Next Row
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Why not import it using Data>From Text?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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