anonymous No title
No License VBA
2021年07月20日
Copy Clone
'ブックモジュール
Option Explicit

Private Sub Workbook_Open()
    Application.OnKey "+^{c}", "inTotal"
    Application.OnKey "+^{+}", "plusTotal"
    Application.OnKey "+^{v}", "outTotal"
    Application.OnKey "+^{*}", "clearTotal"
End Sub


'標準モジュール
Option Explicit

Dim stackSum As Variant

Sub inTotal()
    stackSum = CDec(WorksheetFunction.Sum(Selection))
    Call showStatusBer(stackSum)
End Sub

Sub plusTotal()
    stackSum = stackSum + CDec(WorksheetFunction.Sum(Selection))
    Call showStatusBer(stackSum)
End Sub


Sub outTotal()
    Selection.Value = stackSum
End Sub

Sub clearTotal()
    stackSum = 0
    Application.StatusBar = False
End Sub

Sub showStatusBer(ByVal num As Variant)
    Dim len小数部 As Long:  len小数部 = Len(CStr(num)) - Len(CStr(Int(num))) - 1
    
    If len小数部 <= 0 Then
        Application.StatusBar = "Total = " & Format(num, "#,##0")
    Else
        Application.StatusBar = "Total = " & Format(num, "#,##0." & String(len小数部, "0"))
    End If

End Sub
'ブックモジュール
Option Explicit

Private Sub Workbook_Open()
    Application.OnKey "+^{c}", "inTotal"
    Application.OnKey "+^{+}", "plusTotal"
    Application.OnKey "+^{v}", "outTotal"
    Application.OnKey "+^{*}", "clearTotal"
End Sub


'標準モジュール
Option Explicit

Dim stackSum As Variant

Sub inTotal()
    stackSum = CDec(WorksheetFunction.Sum(Selection))
    Call showStatusBer(stackSum)
End Sub

Sub plusTotal()
    stackSum = stackSum + CDec(WorksheetFunction.Sum(Selection))
    Call showStatusBer(stackSum)
End Sub


Sub outTotal()
    Selection.Value = stackSum
End Sub

Sub clearTotal()
    stackSum = 0
    Application.StatusBar = False
End Sub

Sub showStatusBer(ByVal num As Variant)
    Dim len小数部 As Long:  len小数部 = Len(CStr(num)) - Len(CStr(Int(num))) - 1
    
    If len小数部 <= 0 Then
        Application.StatusBar = "Total = " & Format(num, "#,##0")
    Else
        Application.StatusBar = "Total = " & Format(num, "#,##0." & String(len小数部, "0"))
    End If

End Sub
No one still commented. Please first comment.