首页 文章

在Excel中汇总特定值并在消息框中显示?

提问于
浏览
-1

我有一个Excel,其中包含C列中的所有标记列表 . 我需要一个消息框,它应该计算这些标记的总和,并应该在关闭Excel时显示我(或)如果它在我点击任何快捷键时显示我就可以了 . 我尝试使用下面的代码,但它不起作用:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim answer As Integer
    answer = MsgBox("Do want to see the total?", vbYesNo + vbQuestion, "Total")

        If answer = vbYes Then
          Range("G1").Value = Application.Sum(Range(Cells(3, 2), Cells(3, 3000)))
    Else
        'do nothing
    End If
    End Sub

1 回答

  • 0

    如果你这样做会怎么样

    If answer = vbYes Then
      msgbox(Application.Sum(Range(Cells(2,3), Cells(3000,3)))
    End If
    

    (我改变你的 Cells() 数字,因为你想要C列,而不是第3行 . )

相关问题