Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2334|回复: 8

[已解决]麻烦帮我看看这个问题怎么解决

[复制链接]
发表于 2013-6-3 22:24 | 显示全部楼层 |阅读模式
我表中的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


最佳答案
2013-6-3 23:44
  1. Sub 正则处理()
  2.     Dim objRegExp As Object, item1
  3.     Dim lLastrow&, i&
  4.     Dim arr
  5.     Dim strTemp$

  6.     lLastrow = Cells(Rows.Count, 1).End(xlUp).Row
  7.     arr = Range("c4:c" & lLastrow).Value


  8.     If Not IsArray(arr) Then Exit Sub
  9.     Set objRegExp = CreateObject("VBScript.regExp")
  10.     With objRegExp
  11.         .Global = True
  12.         .Pattern = "\+(\d*\.?\d*)"
  13.         For i = 1 To UBound(arr)
  14.             strTemp = arr(i, 1)
  15.             For Each item1 In .Execute(strTemp)
  16.                 strTemp = Replace(strTemp, item1.Value, Format(Val(item1.submatches(0)), "+0.000"))
  17.             Next
  18.             arr(i, 1) = strTemp
  19.         Next
  20.     End With
  21.     Set objRegExp = Nothing
  22.     Application.ScreenUpdating = False
  23.     Application.DisplayAlerts = False
  24.     Application.EnableEvents = False
  25.     Range("f4").Resize(UBound(arr)).Value = arr
  26.     Columns("f").AutoFit
  27.     Columns("f").HorizontalAlignment = xlLeft
  28.     Application.ScreenUpdating = True
  29.     Application.DisplayAlerts = True
  30.     Application.EnableEvents = True
  31.     MsgBox "ok"
  32. End Sub
复制代码

LM-1路面进度4月快报213.4.rar

31.45 KB, 下载次数: 8

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2013-6-3 23:28 | 显示全部楼层
结合现有数据,举例说明要达到的效果。
回复

使用道具 举报

发表于 2013-6-3 23:44 | 显示全部楼层    本楼为最佳答案   
  1. Sub 正则处理()
  2.     Dim objRegExp As Object, item1
  3.     Dim lLastrow&, i&
  4.     Dim arr
  5.     Dim strTemp$

  6.     lLastrow = Cells(Rows.Count, 1).End(xlUp).Row
  7.     arr = Range("c4:c" & lLastrow).Value


  8.     If Not IsArray(arr) Then Exit Sub
  9.     Set objRegExp = CreateObject("VBScript.regExp")
  10.     With objRegExp
  11.         .Global = True
  12.         .Pattern = "\+(\d*\.?\d*)"
  13.         For i = 1 To UBound(arr)
  14.             strTemp = arr(i, 1)
  15.             For Each item1 In .Execute(strTemp)
  16.                 strTemp = Replace(strTemp, item1.Value, Format(Val(item1.submatches(0)), "+0.000"))
  17.             Next
  18.             arr(i, 1) = strTemp
  19.         Next
  20.     End With
  21.     Set objRegExp = Nothing
  22.     Application.ScreenUpdating = False
  23.     Application.DisplayAlerts = False
  24.     Application.EnableEvents = False
  25.     Range("f4").Resize(UBound(arr)).Value = arr
  26.     Columns("f").AutoFit
  27.     Columns("f").HorizontalAlignment = xlLeft
  28.     Application.ScreenUpdating = True
  29.     Application.DisplayAlerts = True
  30.     Application.EnableEvents = True
  31.     MsgBox "ok"
  32. End Sub
复制代码
回复

使用道具 举报

发表于 2013-6-3 23:45 | 显示全部楼层
结果在F列,你先看看对不对。
回复

使用道具 举报

发表于 2013-6-3 23:45 | 显示全部楼层
正则的替换暂时不太明白,用的REPLACE实现的。
回复

使用道具 举报

 楼主| 发表于 2013-6-4 18:32 | 显示全部楼层

麻烦帮我看看这个问题怎么解决

hwc2ycy 发表于 2013-6-3 23:44


K0+000~K0+090变为K0+000.000~K0+090.000不是K0+0.000~K0+90.000
回复

使用道具 举报

发表于 2013-6-4 18:40 | 显示全部楼层
strTemp = Replace(strTemp, item1.Value, Format(Val(item1.submatches(0)), "+000.000"))

你这是不足三位补三位吧?
回复

使用道具 举报

 楼主| 发表于 2013-6-4 21:30 | 显示全部楼层
那么的帅 发表于 2013-6-3 23:28
结合现有数据,举例说明要达到的效果。

K0+000~K0+090变为K0+000.000~K0+090.000
匝A K0+000~K0+090变为匝A K0+000.000~K0+090.000
回复

使用道具 举报

 楼主| 发表于 2013-6-30 23:40 | 显示全部楼层
我心飞翔410 发表于 2013-6-4 21:30
K0+000~K0+090变为K0+000.000~K0+090.000
匝A K0+000~K0+090变为匝A K0+000.000~K0+090.000

班班 这个题能不能用添加啊 意思就是没小数的添加两位  有一位添加一位
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-26 06:00 , Processed in 0.315496 second(s), 12 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表