如何转换成百分比

时间:2018-11-15 18:50:49

标签: excel excel-formula

请帮助我如何在Excel中将此单元格从数字转换为百分比

  

帐户:银行-全球 0.308123555052582 -互联网内容和   信息 0.307825851134657 -消费电子    0.383936697049749

成为

  

帐户:银行-全球 30.81%-互联网内容和   信息 30.78%-消费类电子产品 38.39%

谢谢。

2 个答案:

答案 0 :(得分:0)

也许下面的VBA解决方案使用Regular Expressions

Function FixMyPercentages(target As String) As String
    Dim output As String
    output = target
    With New RegExp
        .Global = False
        .MultiLine = True
        .IgnoreCase = False
        .pattern = "\s\d+\.\d+$|^\d+\.\d+\s|\s\d+\.\d+\s"

        Dim myMatch As Object, myMatches As Object

        Do While .test(output)
            Set myMatches = .Execute(output)
            For Each myMatch In myMatches
                output = .Replace(output, " " & Format$(CDbl(myMatch.Value), "0.00%") & " ")
            Next myMatch
        Loop
    End With
    FixMyPercentages = Trim(output)
End Function

enter image description here

要实现此目的:

  1. Alt + F11 打开VB编辑器(或 Developer > Visual Basic 。)
  2. 然后插入> 模块
  3. 粘贴以下代码。
  4. 工具> 参考
  5. 下添加对Microsoft VBScript Regular Expressions 5.5的引用
  6. 然后将其用作工作表中的公式。

enter image description here

答案 1 :(得分:0)

@BigBen有一个很好的复杂解决方案。 我可能会做一个“肮脏的解决方法”,例如:

  • 在A列中:查找并用一个分隔符('| 0')替换一个后跟0的空格
  • 插入帮助列B
  • 文本到A列的列,在步骤1中放置的分隔符上拆分
  • 将B列中的单元格设置为%
  • 根据需要重新连接在一起。