Import from txt file.

tknig01

New Member
Joined
Jul 21, 2002
Messages
26
Hi, i'm trying to write a macro that obtains data from a huge database extract. The amount of data would easily exceed excel's capabillity so instead of a straightforward extract, i've dumped the info into a text file so i can import in chunks.

Split into groups using fields in col A (fields are either "alpha" or "beta") the data would fit on to a spreadsheet. Can anyone give me the code to only import rows where col A = alpha in a text file.

Thanks Tom Knight.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You would need to read in the file one line at a time. Something like this (not tested):

Code:
Sub Test()
   Dim r As Long
   Dim Data As String
   Dim Rng As Range
   Set Rng = Range("A1")
   Open "C:TextFile.txt" For Input As #1
   r = 0
   Do While Not EOF(1)
      Line Input #1, Data
      If Left(Data,5) = "Alpha" Then
         Rng.Offset(r,0) = Data
         r = r + 1
      End If
   Loop
   Close #1
End Sub

Amend the target range and text file name to suit. The data will come in as a single column. You can use Text to Columns to parse it.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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