[英]Excel VBA - search and import multiple nested strings from text file
我正在尝试从json数据文本文件中提取一些字符串。 问题是我需要的信息不在唯一的标题下,而是嵌套的。 从下面的示例中可以看到,每个块大小都有3个iothroughput数字。 我该如何找回它们? 我可以搜索字符串并返回行号,但是我无法始终如一地获取正确的数据及其相应的块大小。
块大小:16KB
初始:
iothroughput:500
覆盖:
iothroughput:1000
读:
iothroughput:2000
块大小:64MB
初始:
iothroughput:10
覆盖:
iothroughput:20
读:
iothroughput:30
到目前为止,我有以下代码搜索字符串并返回该行。 然后,我要在该位置开始另一个搜索,以查找“ initial”,返回该行号,并搜索“ iothroughput”,然后将该值放入单元格中。
Sub Import_File()
MsgBox ("Please Insert Data Contention File")
myFile = Application.GetOpenFilename()
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
Text = Text & textline
Dim Ctr, Ctr2, Str
Ctr = Ctr + 1
Str = 16777216
If textline Like "*" & "" & Str & "" & "*" Then
Ctr2 = Ctr
Range("E4").Value = Ctr2
End If
Loop
Close #1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.