问题描述:

How do augment this formula

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

to separate the data below into columns by symptom cause resolution

L=Cannot print in UNIX

Symptom: Cannot print or plot in UNIX Cause: Configuration issue

Resolution: Escalate to the appropriate team Escalation Path: OEMM GIT Desktop References: Keywords: ZEH Created:

网友答案:

I like to get messy and complicated, but this can be done very easy Old fashion style.

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)

If you only have a single space " " to delimit your columns simply use text to column, check Delimited, and hit " " under Other separator, then Finish. And of course, before doing this, you should copy the column (paste/special values on column C, and then breake it to keep the initial values on column B) :) Hope this help.

EDIT

Here is a piece of code that I wrote up (in a bit of a hurry). This follows the example from above with user input for column select and the string of chars used to break the text. If you only need to use space as "text breaker" then enter " " in the second promt. Usually I take time to "clean" the code but this is what 10 minutes produced:

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

Maybe I'll give this code another shot for a facelift (some other time). Hope there's no debuging to be done. I've tested it on Excel 2007. Cheers!

相关阅读:
Top