Hi all
I'm using slightly modified code to import text files to excel. The imported files are basically a list experiment results, however only certain results are important for me.
Some experiments begin with the word "Single test", and these should not be imported. How can I modify my current code to do so?
Heres the code so far:
The problem is I cannot use " If wholeline = "Single test" then .... " because Single test is followed by the experiment name. Additionally eac single test is only 5 lines long, so I was thinking of using something like this:
However Im not sure how to get the macro to ignore this line and the next 4, and move on. Any suggestions on this?
Thanks!
I'm using slightly modified code to import text files to excel. The imported files are basically a list experiment results, however only certain results are important for me.
Some experiments begin with the word "Single test", and these should not be imported. How can I modify my current code to do so?
Heres the code so far:
Code:
Public Sub ImportTextFile(FName As String, Sep As String)
Dim RowNdx As Long
Dim ColNdx As Integer
Dim TempVal As Variant
Dim WholeLine As String
Dim Pos As Integer
Dim NextPos As Integer
Dim SaveColNdx As Integer
Dim StartFlag As Boolean
Application.ScreenUpdating = False
SaveColNdx = ActiveCell.Column
RowNdx = ActiveCell.Row
StartFlag = False
Open FName For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
If WholeLine = "Function" Then
StartFlag = True
End If
If StartFlag = True Then
If Right(WholeLine, 1) <> Sep Then
WholeLine = WholeLine & Sep
End If
ColNdx = SaveColNdx
Pos = 1
NextPos = InStr(Pos, WholeLine, Sep)
While NextPos >= 1
TempVal = Mid(WholeLine, Pos, NextPos - Pos)
Cells(RowNdx, ColNdx).Value = TempVal
Pos = NextPos + 1
ColNdx = ColNdx + 1
NextPos = InStr(Pos, WholeLine, Sep)
Wend
RowNdx = RowNdx + 1
End If
Wend
Set Borderrange = Range("A3:AZ2000")
For Each c In Borderrange.Cells
If c.Value = "END" Then c.EntireRow.Borders(xlEdgeBottom).LineStyle = XlLineStyle.xlContinuous
Next c
Dim LastCol As Long
LastCol = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Columns(LastCol).Borders(xlEdgeRight).LineStyle = XlLineStyle.xlContinuous
Cells(1, LastCol).Offset(0, 2).Select
EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #1
End Sub
The problem is I cannot use " If wholeline = "Single test" then .... " because Single test is followed by the experiment name. Additionally eac single test is only 5 lines long, so I was thinking of using something like this:
Code:
If WholeLine = "Single Test" + "*" Then ...
However Im not sure how to get the macro to ignore this line and the next 4, and move on. Any suggestions on this?
Thanks!