|
试试
Sub test()
Cells.Clear
Open ThisWorkbook.Path & "/2.txt" For Input As #1
k1% = 1: k2% = 6: k3% = 1
r% = 1: c% = 0
Do While Not EOF(1)
Line Input #1, sl$
sl = Replace(Trim(sl), Chr(10), "")
If Len(sl) Then
For Each tmp In Split(sl, " ")
If Len(tmp) Then
n1 = n1% + 1
If k1 = 1 Then
If n1 <= 6 Then
c = c + 1
Else
k2 = Cells(r, c) + 1
k3 = Cells(r, c - 1)
r = r + 1
c = 2
k1 = 0
n1 = 1
End If
Else
If n1 <= k2 Then
c = c + 1
Else
k3 = k3 - 1
r = r + 1
n1 = 1
If k3 Then
c = 2
Else
c = 1
k1 = 1
End If
End If
End If
Cells(r, c) = tmp
End If
Next
End If
Loop
Close #1
End Sub |
|