|
可能你喜欢这样的:
Sub 行列汇总()
Dim rng As Range, GatherStyle As Long, GatherStr As String
Set rng = Application.InputBox("请指定待求和的区域", "区域", , , , , , 8)
GatherStyle = Application.InputBox("输入1:求和" & Chr(13) & "输入2:求积" & Chr(13) & "输入3:求平均" & Chr(13) & "输入4:计数", "汇总方式", , , , , , 1)
GatherStr = Evaluate("=vlookup(" & GatherStyle & ",{1,""SUM"";2,""PRODUCT"";3,""AVERAGE"";4,""COUNTA""},2,false)")
rng.Offset(, rng.Columns.Count).Columns(1).FormulaR1C1 = "=" & GatherStr & "(RC[-" & rng.Columns.Count & "]:RC[-1])"
rng.Offset(rng.Rows.Count).Rows(1).FormulaR1C1 = "=" & GatherStr & "(R[-" & rng.Rows.Count & "]C:R[-1]C)"
End Sub
|
|