分隔成单元格内的新行

我想修改/格式化单元格中的文本,如: 这是我不想要的格式化文本

如果文本包含“;” 或子弹,做一个新的行。

简而言之,我将该单元格复制到noteped(.txt)中,并将多个项目符号复制到一行或“;”中。 我想创造一个新的行。 现在,我手动修改它。

谢谢!

编辑:

Sub foo1() Dim txt As String Dim i As Integer Dim FullName As Variant Dim oldText As String txt = Cells(2, 5) FullName = Split(txt, ";") For i = 0 To UBound(FullName) oldText = Cells(2, 1).Value Cells(2, 1).Value = oldText & vbCrLf & "•" & FullName(i) Next End Sub 

我已经成功了 只有两个问题:1.如何设置两个分隔符? 2.为什么当我把单元格的值复制到记事本中时,用“”来包装它?

如果你想在多个单元格中:

 Sub fool() Dim txt as String, txt2 as variant txt = Replace(Cells(2, 5), ".", ";") txt2 = Split(txt, ";") Range(Cells(2, 1), Cells(Ubound(txt2) + 2, 1) = _ Application.WorksheetFunction.Transpose(txt2) End Sub 

如果你想在一个单元格中的所有人:

 Sub fool() Dim txt as String txt = Replace(Cells(2, 5), ".", vbCrLf) txt = Replace(txt, ";", vbCrLf) Cells(2, 1) = txt End Sub 

嗯…如果你想保留旧的文本在单元格(2,1),然后更改最后一行为:

  Cells(2, 1) = Cells(2, 1) & vbCrLf & txt 

编辑:或者一个干净的方式:

 Sub fool() Dim txt As String, i As Byte txt = Cells(2, 1) & vbCrLf & Cells(2, 5) 'change all delimeters For i = 0 To 2 txt = Replace(txt, Array(".", ";", "•")(i), vbCrLf) Next 'eliminate doubles Do While InStr(txt, vbCrLf) > 0 txt = Replace(txt, vbCrLf & vbCrLf, vbCrLf) Loop Cells(2, 1) = txt End Sub