请帮助我如何在Excel中将此单元格从数字转换为百分比
帐户:银行-全球 0.308123555052582 -互联网内容和 信息 0.307825851134657 -消费电子 0.383936697049749
成为
帐户:银行-全球 30.81%-互联网内容和 信息 30.78%-消费类电子产品 38.39%
谢谢。
答案 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
要实现此目的:
Microsoft VBScript Regular Expressions 5.5
的引用
答案 1 :(得分:0)
@BigBen有一个很好的复杂解决方案。 我可能会做一个“肮脏的解决方法”,例如: