0

I have a column (A) of values that I would like to trim to the left. Each value in column A has a / in it which separates a word in German and it's English translation. For example one value would be "nein / no". (note there is a space between the two words.

What I want to do is write a trim function that starts after the space that follows the /. In othe words I want the value in my example to trim from "nein / no" to just "no". The part that confuses me is the fact that each value changes in size so I don't know how to tell excel where to trim from. My code should look something like this

For each cl in range("A1:A300"). Trim cl.value. Next cl
4

3 回答 3

2

试试下面的代码:

Dim start As Long

    For Each cl In Range("A1:A300")
        str = c1

        start = InStr(1, str, "/", vbTextCompare) + 1

        strVal = Trim(Right(str, Len(str) - start))
        msgbox strVal 
    Next cl
于 2013-05-22T18:43:50.817 回答
1

从这样的事情开始:

For each cl in Range("A1:A300")
    With cl
        .Value = Trim(Len(.Value) - Right(.Value, _
             Application.WorksheetFunction.Find("/", .Value)))
    End With
Next
于 2013-05-22T18:42:05.040 回答
1

你不需要 VBA 来解决这个问题。一个简单的公式就足够了:

=RIGHT(A1,LEN(A1)-FIND(" ",A1,FIND(" ",A1)+1))

nein / no = no


皮裤/马裤=马裤


分身/分身=分身

于 2013-05-22T18:42:59.330 回答