|
我表中的K0+000~K0+140.0 我想把这些乱的数据变规律 变为K0+000.00~K0+140.00 匝A K0+131.84~K0+223.71
这种格式保留匝A 后面也变为匝A K0+000.00~K0+140.00
- Sub 正则处理()
- Dim objRegExp As Object, item1
- Dim lLastrow&, i&
- Dim arr
- Dim strTemp$
- lLastrow = Cells(Rows.Count, 1).End(xlUp).Row
- arr = Range("c4:c" & lLastrow).Value
- If Not IsArray(arr) Then Exit Sub
- Set objRegExp = CreateObject("VBScript.regExp")
- With objRegExp
- .Global = True
- .Pattern = "\+(\d*\.?\d*)"
- For i = 1 To UBound(arr)
- strTemp = arr(i, 1)
- For Each item1 In .Execute(strTemp)
- strTemp = Replace(strTemp, item1.Value, Format(Val(item1.submatches(0)), "+0.000"))
- Next
- arr(i, 1) = strTemp
- Next
- End With
- Set objRegExp = Nothing
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Application.EnableEvents = False
- Range("f4").Resize(UBound(arr)).Value = arr
- Columns("f").AutoFit
- Columns("f").HorizontalAlignment = xlLeft
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- Application.EnableEvents = True
- MsgBox "ok"
- End Sub
复制代码
|
|