算的是红框占绿框的百分比
难点在保留原数据的情况下,把百分比加在后面。通过公式我是不会,但程序实现也不难。
先在Excel中的开发工具中打开visual basic,或者用宏也可以
导入代码文件,代码在最后
导入后点击绿色三角形,运行即可
选择需要计算的区域
点击确定后自动完成计算并修改
搞定!
代码
Attribute VB_Name = "模块1"
Sub cal1()
Dim range1 As Range
Set range1 = Application.InputBox("选择区域", Type:=)
x = range1.Rows.Count
y = range1.Columns.Count Dim chushu As Integer
Dim he As Integer
Dim result As String
Dim cut As Integer cut = For t = To x
If range1(t).Value = "" Then
Exit For
End If
he = For i = To y -
he = he + Val(range1(cut + i))
Next i For i = To y -
chushu = Val(range1(cut + i))
result = chushu & "(" & Application.Round((chushu / he) * , ) & "%)"
range1(cut + i) = result
Next i
cut = cut + y
Next t End Sub
欢迎关注↓↓↓
头条号:小锋学长
微信公众号:xfxuezhang