如果没有分隔符字符串,(@Jeeped 提到零宽度空格),那么您可以使用普通字符串函数,如 Mid 和 Instr 来解析它。我把输出放在一个新的工作表上:
Sub foo()
Dim findType As Integer
Dim findProperties As Integer
Dim findDescription As Integer
Dim rng As Range
Dim r As Range
Dim i As Integer
Dim newSheet
Set rng = Range("A1:A3")
'Add a new sheet and put some header rows on it
Set newSheet = Sheets.Add
newSheet.Range("A1").Value = "Type"
newSheet.Range("B1").Value = "Properties"
newSheet.Range("C1").Value = "Description"
i = 1
For Each r In rng.Cells
findType = InStr(1, r.Value, "Type")
findProperties = InStr(1, r.Value, "Properties")
findDescription = InStr(1, r.Value, "Description")
'## Print some output values to a new worksheet
With newSheet
i = i + 1
.Range("A" & i).Value = Mid(r.Value, findType + 4, findProperties - (findType + 4))
.Range("B" & i).Value = Mid(r.Value, findProperties + 10, findDescription - (findProperties + 10))
.Range("C" & i).Value = Mid(r.Value, findDescription + 11)
End With
Next
End Sub
这是将其放在同一个工作表上的替代方法(未经测试):
Sub foo2()
Dim findType As Integer
Dim findProperties As Integer
Dim findDescription As Integer
Dim typeStr as String, propStr as String, descStr as String
Dim rng As Range
Dim r As Range
Dim i As Integer
Set rng = Range("A1:A3")
i = 1
For Each r In rng.Cells
findType = InStr(1, r.Value, "Type")
findProperties = InStr(1, r.Value, "Properties")
findDescription = InStr(1, r.Value, "Description")
i = i + 1
typeStr = Mid(r.Value, findType + 4, findProperties - (findType + 4))
propStr = Mid(r.Value, findProperties + 10, findDescription - (findProperties + 10))
descStr = Mid(r.Value, findDescription + 11)
rng.Value = typStr
rng.Offset(0,1).Value = propStr
rng.Offset(0,2).Value = descStr
Next
Range("A1").EntireRow.Insert
Range("A1").Value = "Type"
Range("B1").Value = "Properties"
Range("C1").Value = "Description"
End Sub