如何将此string拆分为电子表格中的单独列?

从networking上下载数据后,我有以下一组数据。 原始数据应该是Type为“preference”,属性为“Create,Filter,Group,Nillable,Sort,Update”,描述为“ID”。

TypereferencePropertiesCreate, Filter, Group, Nillable, Sort, UpdateDescriptionID TypereferencePropertiesCreate, Filter, Group, Nillable, Sort, UpdateDescriptionID of the account associated with this opportunity. TypecurrencyPropertiesCreate, Filter, Nillable, Sort, UpdateDescriptionEstimated total sale amount. 

有在线教程来教导如何使用分隔符(例如电子表格中的“,空格或其他符号”)分隔string,但是我的数据集是不同的。 如何将“types”,“属性”和“描述”分开?

如果没有分隔string(@Jeeped提到一个零宽度空间),那么你可以使用普通的string函数,如MidInstr来parsing这个。 我把输出放在一个新的工作表中:

 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 

这是一个备用,它放在同一个工作表(未经testing):

 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