c数字
400 字
2 分钟
c数字
c数字
Sub 千分位符(control As IRibbonControl) '数字-千分位符 On Error Resume Next 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 IsNumeric(i) Then 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 NC = Format(i, "#,##0.00;-#,##0.00; ") i.Text = NC Else NC = Format(i, "#,##0.00;-#,##0.00; ") i.Text = NC End If End If End If Next i ElseIf Selection.Type = 4 Or Selection.Type = 5 Then '竖形表格(5为横形表格) For Each Acell In Selection.Cells Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1) ' MsgBox CR If CR Like "-####*" Or "-####.#*" = True Then Yn = Format(CR, "#,##0.00;-#,##0.00; ") CR.Text = Yn Else If CR Like "####*" Or "####.#*" = True Then Yn = Format(CR, "#,##0.00;-#,##0.00; ") CR.Text = Yn End If End If Next Acell Else MsgBox "您只能选定文本或者表格之一!", vbOK + vbInformation End If Application.ScreenUpdating = True Application.ActivateEnd SubSub 除以一万(control As IRibbonControl) Application.ScreenUpdating = False If Selection.Type = 2 Then If IsNumeric(Selection.Text) Then i = Selection.Text P = i / 10000 q = Format(Round(P, 2), "#,##0.00;-#,##0.00; ") Selection.Text = q & "万" End If ElseIf Selection.Type = 5 Or Selection.Type = 4 Then For Each Acell In Selection.Cells Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1) 'MsgBox CR If IsNumeric(CR.Text) Then i = CR.Text P = i / 10000 q = Format(Round(P, 2), "#,##0.00;-#,##0.00; ") CR.Text = q & "万" End If Next End If Application.ScreenUpdating = TrueEnd SubSub 乘百(control As IRibbonControl) Application.ScreenUpdating = False If Selection.Type = 2 Then If IsNumeric(Selection.Text) Then i = Selection.Text P = i * 100 q = Format(Round(P, 2), "#,##0.00;-#,##0.00; ") Selection.Text = q & "%" End If ElseIf Selection.Type = 5 Or Selection.Type = 4 Then For Each Acell In Selection.Cells Set CR = ActiveDocument.Range(Acell.Range.Start, Acell.Range.End - 1) 'MsgBox CR If IsNumeric(CR.Text) Then i = CR.Text P = i * 100 q = Format(Round(P, 2), "#,##0.00;-#,##0.00; ") CR.Text = q & "%" End If Next End If Application.ScreenUpdating = TrueEnd Sub支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!
相关文章智能推荐
1
【VBA案例001】实现VLOOKUP功能
程技2023-10-23
2
【VBA案例002】一对多查询
程技2023-10-23
3
【VBA案例003】模糊查询
程技2023-10-23
4
【VBA案例004】自动填充表单
程技2023-10-23
5
【VBA案例005】自动汇总表单
程技2023-10-23
随机文章随机推荐
樊笼










