如何添加到公式中以分隔成列

时间:2013-11-14 11:35:02

标签: excel vba excel-vba

如何增加此公式

=IF(ISERROR(FIND(" ",TRIM(A1),1)),TRIM(A1),MID(TRIM(A1),FIND(" ",TRIM(A1),1),LEN(A1)))

通过症状原因解决将下面的数据分成列

L=Cannot print in UNIX

症状:无法在UNIX中打印或绘图原因:配置问题

解决方案:升级到相应的团队升级路径:OEMM GIT桌面参考:关键字:ZEH创建:

1 个答案:

答案 0 :(得分:0)

我喜欢弄乱和复杂,但这可以很容易地做旧时尚风格。

hit Ctrl H 
replace your multiple line break chars (i.e. "1234") with a single wild char "~" or "}" are usually good
use Excel's feature "text to columns" to break the line based on your wild char separator. (ctrl +A, +E)

如果您只有一个空格“”来分隔您的列,只需使用text to column,选中Delimited,然后在Other separator下点击“”,然后单击Finish。 当然,在执行此操作之前,您应该复制列(在C列上粘贴/特殊值,然后将其断开以保持B列的初始值):) 希望这有帮助。

修改

这是我写的一段代码(有点匆忙)。这是上面的示例,用户输入列选择字符串用于打破文本。如果您只需要使用空格作为“文本断路器”,则在第二个promt中输入“”。 通常我需要时间来“清理”代码,但这是10分钟后产生的:

Sub SplitColumns()

DestinationColumn = InputBox("Please enter the name of the column you on which you want to perform the split", _
                "Column Selection", "A", 100, 100)

Dim ReplaceRange As Range: Set ReplaceRange = ActiveSheet.Range(DestinationColumn & ":" & DestinationColumn)

SeparatorString = InputBox("Please enter the string of charatesrs used to define the split", _
                "String Definition", "anything goes", 100, 100)

' Please be carefull and check for anythinkg like "~" as it will produce errors if found within the cell text

Dim Response As Integer
Response = MsgBox(prompt:= _
        "Are you sure you want to split the text from column [" & DestinationColumn & "] based on [" & SeparatorString & "] ?" & vbNewLine & _
        "Once the macro is run, there is no Undo Option available(Ctrl+Z)", _
        Buttons:=vbYesNo)
If Response = vbYes Then
ReplaceRange.Replace _
    What:=SeparatorString, _
    Replacement:="~", _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    MatchCase:=False, _
    SearchFormat:=False, _
    ReplaceFormat:=False

ReplaceRange.TextToColumns _
    Destination:=Range(DestinationColumn & "1"), _
    DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, _
    OtherChar:="~", _
    FieldInfo:=Array(Array(1, 1), Array(2, 1)), _
    TrailingMinusNumbers:=True
End If

End Sub

也许我会给这个代码另外一次换脸(其他时间)。 希望没有必要进行调整。我在Excel 2007上测试了它。干杯!