Excel精英培训网

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

[已解决]word文本中数据保留1位小数

[复制链接]
发表于 2014-9-12 09:50 | 显示全部楼层 |阅读模式
Sub CurrencyNumber()
'文本分位符+2位小数
Dim i As Range, Acell As Cell, CR As Range
On Error Resume Next
Application.ScreenUpdating = False
If Selection.Type = 2 Then
For Each i In Selection.Words
If i Like "####*" = True Then
If i.Next Like "." = True And i.Next(wdWord, 2) Like "#*" = True Then
i.SetRange Start:=i.Start, End:=i.Next(wdWord, 2).End
i = Format(i, "Standard")
Else
i = Format(i, "Standard")
End If
End If
Next i
ElseIf Selection.Type = 5 Then
For Each Acell In Selection.Cells
Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1)
MsgBox CR
If CR Like "####*" = True Then
If CR Like "####.#*" = True Then
Yn = Format(CR, "Standard")
CR.Text = Nn
Else
Yn = Format(CR, "Standard")
CR.Text = Nn
End If
End If
Next Acell
Else
MsgBox "您只能选定文本或者表格之一!", vbOK + vbInformation
End If
Application.ScreenUpdating = True

End Sub

上述语句为对word文本中选定的数值添加分位符并保留2位小数,如果需要保留1位小数,如何修改语句?谢谢



最佳答案
2014-9-12 09:57
Yn = Format(CR, "Standard") 这样的语句修改后面的"standard"就可以了吧。
发表于 2014-9-12 09:57 | 显示全部楼层    本楼为最佳答案   
Yn = Format(CR, "Standard") 这样的语句修改后面的"standard"就可以了吧。
回复

使用道具 举报

发表于 2014-9-12 11:57 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-29 05:59 , Processed in 0.229686 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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