The following macro was kindly written by Jerry Beaucaire and works wonderfully.
However, I now find that I am getting files, which I have to change, where the detail for changing is neither on the 5th or 6th but is on the 4tth and in one case the 7th. Therefore is it possible the macro can be adapted so it asks the user to enter the number of the line to be changed and the macro runs and gets that line of information. Many thanks.
Sub ExtractStringFromFiles()
Dim fPATH As String, fNAME As String, buf As String, fNUM As Long, NR As Long
With ThisWorkbook.Sheets("Sheet1")
fPATH = .Range("F2").Value
If Right(fPATH, 1) <> "\" Then fPATH = fPATH & "\"
If MsgBox("Clear existing NC list?", vbYesNo, "Remove prior list") = vbYes Then
.Range("A5:B" & .Rows.Count).ClearContents
NR = 5
Else
NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
End If
fNAME = Dir(fPATH & "*.nc")
Do While Len(fNAME) > 0
fNUM = FreeFile
Open fPATH & fNAME For Input As fNUM
Line Input #fNUM, buf
Line Input #fNUM, buf
Line Input #fNUM, buf
Line Input #fNUM, buf
Line Input #fNUM, buf
If InStr(Trim(buf), "-") = 0 Then Line Input #fNUM, buf
If InStr(Trim(buf), "-") = 0 Then Line Input #fNUM, buf
.Range("A" & NR).Value = fNAME
.Range("B" & NR).Value = Trim(buf)
Close fNUM
NR = NR + 1
fNAME = Dir
Loop
NR = NR - 1
.Range("C6:F" & .Rows.Count).ClearContents
.Range("C5").Copy .Range("C6:C" & NR)
.Range("F5").Copy .Range("F6:F" & NR)
End With
End Sub
Bookmarks