PDA

View Full Version : [SOLVED] Extract specific lines from text file



YasserKhalil
07-01-2017, 10:00 AM
Hello everyone
I have a text file and I need to extract those lines with capital letters (Upper Case) only to my sheet
Thanks advanced for help

mdmackillop
07-01-2017, 10:30 AM
Probably not foolproof in the third test to eliminate numbers

Sub AllCaps()
Dim FileNum As Integer
Dim DataLine As String


FileNum = FreeFile()
Open "C:\VBAX\Sample.txt" For Input As #FileNum


While Not EOF(FileNum)
Line Input #FileNum, DataLine ' read in data 1 line at a time
If DataLine = UCase(DataLine) And Len(DataLine) > 0 And UBound(Split(DataLine, "-")) <= 1 Then
i = i + 1
Cells(i, 1) = DataLine
End If
Wend
End Sub

YasserKhalil
07-01-2017, 10:36 AM
That's amazing Mr. mdmackillop (http://www.vbaexpress.com/forum/member.php?87-mdmackillop)
Thanks a lot for this wonderful solution ... It works like charm