|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
方法二
- Sub 去除首尾加号()
- Dim nRow As Long, vData As Variant, oRegExp As Object, nRegExp As Long
-
- With [DD1].Resize(Cells(Rows.Count, "DD").End(xlUp).Row)
- vData = .Value
- With CreateObject("Vbscript.RegExp")
- .Global = True
- .IgnoreCase = True
- .Pattern = "(\++)?[^+]+"
- For nRow = 1 To UBound(vData)
- Set oRegExp = .Execute(vData(nRow, 1))
- If oRegExp.Count > 0 Then
- vData(nRow, 1) = Empty
- For nRegExp = 0 To oRegExp.Count - 1
- If nRegExp = 0 Then
- vData(nRow, 1) = Replace(oRegExp(0), "+", "")
- Else
- vData(nRow, 1) = vData(nRow, 1) & oRegExp(nRegExp).Value
- End If
- Next
- End If
- Next
- End With
- .Offset(, 2).Formula = vData
- End With
- End Sub
复制代码 |
|