Selected Answer
Hi Jaysan and welcome to the Forum.
You didn't embed a source file so I'm guessing (from your Replace statements) that you have text files of several lines with data separated by spaces like this:
Head W X Y Z
$ a b c d
A B C D
$ 1 2 3 4
$ 5 6 7 8
and you want to import only those starting with $. (Bear with me please...)
In the code below, I defined a new variable MyArray (which simplifies the Ubound line andthat writing to cells) and made both the Replace and Split methods have the semicolon ";" (i.e. replace spaces in the text line with a semi-colon then split that string into an array using the semi-colon as the division) . See changes in bold (including commenting out lines using "start"- which may be wrong- see text below code):
Sub checkATT()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
Sheets(2).Range("A2:W1048576").ClearContents
Sheets(2).Range("X4:AF1048576").ClearContents
Dim ATTFile As Object, filepath As String, textline As String, start As Integer, i As Integer, j As Double
Dim MyArray As Variant
j = 2
filepath = ThisWorkbook.Path & "\" & Sheets(1).Range("D1048576").End(xlUp).Value
Open filepath For Input As #1
Do Until EOF(1)
Line Input #1, textline
If Left(textline, 1) = "$" Then 'start = start + 1
'If start = 2 Then
MyArray = Split(Replace(CStr(textline), " ", ";"), ";")
For i = 0 To UBound(MyArray)
Sheets(2).Cells(j, i + 1) = MyArray(i)
Next i
j = j + 1
End If
Loop
Close #1
Sheets(2).Range("X3:AF3").Copy
Sheets(2).Range("X4:AF" & Sheets(2).Range("A1048576").End(xlUp).Row).PasteSpecial xlPasteFormulas
Sheets(1).Range("S1") = "Table based on ATT File " & Chr(34) & Sheets(1).Range("D1048576").End(xlUp).Value & Chr(34)
Application.CalculateFull
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True
End Sub
That modified code is in the attached revised file.
If however you want to import all text after the first line strting with $, then restore the code for "
start" but change the test to read:
'If start >= 2 Then
Hope this fixes things for you. If so, please remember to mark this Answer as
Selected.