VBA文本到带有分隔符的列

我会很快。

我有一个带有文本的variables“strLine”:

确切的string将如下所示:

"Text1","Text2","Text3","Text4","Text5"

所以,在我的情况下,分隔符是:“

我如何提取文本并将其写入列。

期望在单元格中的结果:

 A1=Text1 B1=Text2 C1=Text3 D1=Text4 E1=Text5 

谢谢

使用Splitfunction,它会返回一个基于0的数组(单元格中的ergo +1):

 Sub test_Andy() Dim StrLine As String Dim Str() As String StrLine = Range("A2").Value 'If your value is in A2 'If you input the value manually, not really practical with so much " StrLine = Chr(34) & "Text1" & Chr(34) & "," & Chr(34) & "Text2" & Chr(34) & "," & Chr(34) & "Text3" & Chr(34) & "," & Chr(34) & "Text4" & Chr(34) & "," & Chr(34) & "Text5" & Chr(34) Debug.Print StrLine '"Text1","Text2","Text3","Text4","Text5" Str = Split(StrLine, ",") Dim i As Integer For i = LBound(Str) To UBound(Str) Cells(1, i + 1) = Str(i) Cells(2, i + 1) = Replace(Str(i), Chr(34), vbNullString) Next i End Sub 

您可以使用Split将文本拆分成一个数组,然后删除"从零件的开始和结束使用Mid

 strText = """Text1"",""Text2"",""Text3"",""Text4"",""Text5""" aSplit = Split(strText, ",") For Each strCurrent in aSplit MsgBox Mid(strCurrent, 2, Len(strCurrent) - 2) Next 

备注:您可能需要添加一些检查来确保在删除它们之前有一个"开始和结束”。

编辑模拟一个StrLine循环:

 Dim iRow As Long irow = 1 For Each StrLine In StrLines '<--' assuming a loop through many StrLines Str = Split(Replace(StrLine, """", ""), ",") Cells(iRow, 1).Resize(, UBound(Str) - LBound(Str)).Value = Str iRow = iRow + 1 Next