|
エクセルの並べ替え機能を使ってみました。
例示されているようなデータで間違いなければ、うまくいくはずですが。
Sub MyTxt_Sort()
Dim MyF As String, buf As String
Dim i As Long
Dim Ary As Variant
With Application
MyF = .GetOpenFilename("テキストファイル(*.txt),*.txt")
If MyF = "False" Then Exit Sub
.ScreenUpdating = False
End With
Cells.ClearContents: On Error GoTo Eline
Open MyF For Input Access Read As #1
Do Until EOF(1)
Line Input #1, buf
Select Case True
Case Left$(buf, 1) = "["
i = i + 1: Ary = Split(buf, Chr(32))
Cells(i, 1).Value = Ary(1)
Erase Ary
Case Left$(buf, 1) Like "[A-Z]"
Ary = Split(buf, Chr(32))
If CSng(Ary(1)) > 9.45 Then
Ary = WorksheetFunction.Transpose(Ary)
Cells(i, 256).End(xlToLeft).Offset(, 1) _
.Resize(2).Value = Ary
End If
Erase Ary
Case Left$(buf, 1) = "}"
Range(Cells(i, 2), Cells(i + 1, 256).End(xlToLeft)) _
.Sort Key1:=Rows(i + 1), Order1:=xlDescending, _
Header:=xlNo, Orientation:=xlSortRows
Rows(i + 1).ClearContents
Case Else: Debug.Print Asc(Left$(buf, 1))
End Select
Loop
Eline:
Close #1
If Err.Number = 0 Then
MsgBox Dir(MyF) & " の読み込みを終了しました", 64
Else
MsgBox "エラー発生", 48
End If
Application.ScreenUpdating = True
End Sub
|
|