我正在逐行读取一个csv文件,并使用Split()函数对其进行拆分。这部分工作正常,但是,我实际上只是在搜索以“ MONITORED”开头的行。当我尝试比较数组的第一个元素时,出现下标超出范围错误。
Open Fname For Input As #1
iRow = 1
Line Input #1, Record
Do Until EOF(1)
P = Split(Record)
If P(0) = "MONITORED" Then
For i = LBound(P) To UBound(P)
Cells(iRow, i + 1) = P(i)
Next i
Else
iRow = iRow - 1
End If
iRow = iRow + 1
Line Input #1, Record
Loop
Close 1
答案 0 :(得分:0)
一些更改:
Open Fname For Input As #1
iRow = 1
Do While Not EOF(1)
Line Input #1, Record
If Record Like "MONITORED*" Then
p = Split(Record, ",")
Cells(iRow, 1).Resize(1, UBound(p) + 1) = p
iRow = iRow + 1
End If
Loop
Close 1