Hey all,
I need help to integrate 'make cell blank if there is an error' into my existing code.
Currently, when I get an error, the macro will use the cell value of the most recent non-error cell. What happens is that I will get duplicate entries for all my error cells, until a non-error text is read.
Anyone knows how to integrate the leave blank cell if error into my existing code?
Code:
Sub all3()
Dim myfile
Dim FSO As FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Res As String, temp As String
myfile = Application.GetOpenFilename("Txt files (*.txt), *.txt", , "Please select your file or files", , True)
Dim x As Long
Dim y As Long
y = 1
If IsArray(myfile) Then
For x = LBound(myfile) To UBound(myfile)
temp = FSO.GetFile(myfile(x)).OpenAsTextStream.ReadAll
On Error Resume Next
Res = Left(Mid(temp, InStr(1, temp, "2. ", vbTextCompare)), InStr(Mid(temp, InStr(1, temp, "2. ", vbTextCompare)), vbLf))
Range("E" & y).Value = Res
y = y + 1
Next
End If
Set FSO = Nothing
End Sub
Bookmarks