0

次のサンプルを含むセルの列があります

a1 = D11F2/J3C2/FENCE*25A/23A/21A/20A
a2 = d11f2/00A/123/d6f2

3 桁のコード "/00A" を削除したいのですが、通常は / で区切られていますが、A1 の場合と同様に、星印 "*25a" で区切られています。

この数式/マクロは次のようになります。

a1 = D11F2/J3C2/FENCE
a2 = d11f2/d6f2

助けてくれてありがとう!

代替式を使用してみましたが、除算器の後の最初または2番目の文字列のみを削除しました

4

2 に答える 2

0

次の VBA 関数は、あなたが求めていることを理解しているようです。

Function stripThree(s As String)
' find any sequence of three "digits"
' that are separated by either ' ', '*', or '/'
' and remove them, including their leading separator

Dim ii, l, lastGood, lastSep As Integer
Dim retval As String

lastGood = 0
lastSep = 0

For ii = 1 To Len(s)
  l = Mid(s, ii, 1)
  retval = retval & l
  If l = "/" Or l = "*" Or l = " " Then
    If ii - lastSep = 4 Then
      retval = Left(retval, Len(retval) - 5) & l
    End If
    lastSep = ii
  End If
Next ii

' if last "separator" is the end of the string
' we still need to remove the three digit/letter code
If lastSep + 4 = ii Then
  retval = Left(retval, Len(retval) - 4)
End If


stripThree = retval

End Function

作業中のこのコードの例:

input:  D11F2/J3C2/FENCE*25A/23A/21A/20A
output: D11F2/J3C2/FENCE

input:  d11f2/00A/123/d6f2
output: d11f2/d6f2

質問に規定されているとおりです。

于 2013-04-05T20:36:37.633 に答える