import 1 line from txt file

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
262
Office Version
  1. 2010
Platform
  1. Windows
With ActiveSheet.QueryTables.Add(Connection:="TEXT;T:\JICU20190512123222.txt" _
, Destination:=Range("$A$1"))
.Name = "JICU20190512123222"
.TextFilePlatform = 850
.TextFileStartRow = 4
.TextFileParseType = xlDelimited
.TextFileSemicolonDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 9)
.Refresh BackgroundQuery:=False


ok so I have a huge txt file but all I need is one line.
Line 4 has 3 columns of important info that I need to import
At the moment I resolved to delete anything below 4

Is there a cleaner way
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this

Code:
Sub test_line()
    Dim LineofText As Variant, wFile As String, n As Long
    wFile = "C:\trabajo\otro.txt"
    n = 1
    Open wFile For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
    Do While Not EOF(1)
        Line Input [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , LineofText
        If n = 4 Then
            cols = Split(LineofText, ";")
            Range("A1:C1").Value = Array(cols(0), cols(1), cols(2))
            Exit Do
        End If
        n = n + 1
    Loop
    Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
End Sub

OR

Code:
[COLOR=#333333]With ActiveSheet.QueryTables.Add(Connection:="TEXT;T:\JICU20190512123222.txt" _[/COLOR]
[COLOR=#333333], Destination:=Range("$A$1"))[/COLOR]
[COLOR=#333333].Name = "JICU20190512123222"[/COLOR]
[COLOR=#333333].TextFilePlatform = 850[/COLOR]
[COLOR=#333333].TextFileStartRow = 4[/COLOR]
[COLOR=#333333].TextFileParseType = xlDelimited[/COLOR]
[COLOR=#333333].TextFileSemicolonDelimiter = True[/COLOR]
[COLOR=#333333].TextFileColumnDataTypes = Array(1, 1, 1, 9)[/COLOR]
[COLOR=#333333].Refresh BackgroundQuery:=False
[/COLOR]end with

[COLOR=#0000ff]rows("2:" & rows.count).clearcontents[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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