|
参考例です。
Sub test()
Dim dic As Object
Dim re As Object
Dim s As String
Dim filename As String
Dim mat() As String ' 結果を書き出すための配列
Dim k As Long
Dim p As Long
Dim matches As Object
Dim s1 As String
Dim s2 As String
Dim s3 As String
Set dic = CreateObject("Scripting.Dictionary")
Set re = CreateObject("VBScript.RegExp")
re.Pattern = "edit (\d+)|\s*set\s*(\S*)\s*(.*)"
filename = "D:\MyDocuments\201711\test.txt" '■要修正
k = 0
p = 1
Open filename For Input As #1
Do While Not EOF(1)
Line Input #1, s
If s <> "next" And s <> "" Then
Set matches = re.Execute(s)
s1 = matches(0).SubMatches(0) ' editの後の数値
s2 = matches(0).SubMatches(1) ' キー項目
s3 = matches(0).SubMatches(2) ' 対応する値
If s1 <> "" Then
k = k + 1
ReDim Preserve mat(1 To 20, 1 To k) '項目数は20個が上限とした
mat(1, k) = s1
Else
If Not dic.exists(s2) Then
p = p + 1
dic(s2) = p
End If
mat(dic(s2), k) = s3
End If
End If
Loop
Close #1
'結果の書き出し
[A1].Value = "ID"
[B1].Resize(1, p - 1) = dic.keys
[A2].Resize(k, 20).Value = Application.Transpose(mat)
End Sub
修正依頼にはお応えできませんので、悪しからず。
|
|