VBA Excel基于单元格值运行报警消息列表

时间:2018-05-30 18:08:02

标签: excel vba message alarm

我有一个警报消息列表,我希望在单元格K5中显示,具体取决于单元格H5中的值。我在模块中有这个代码。

Sub Display_Alarm_Descriptions()
    Dim alarmNumber As Integer, alarmMsg As String
    alarmNumber = Range("H5").Value
    If alarmNumber = 0 Then alarmMsg = "No Active Alarms"
    If alarmNumber = 1 Then alarmMsg = "Proofer Output Failure Safety"
    If alarmNumber = 2 Then alarmMsg = "Main Drive Overload"
    Range("K5").Value = alarmMsg

End Sub

我想要添加的是H5中的值更改时的时间戳的运行列表,H5的新值是什么以及来自K5的相关警报消息。如果H5发生变化,我想在下面的下一个可用单元格中找到新信息(时间戳,H5值和警报信息)。

1 个答案:

答案 0 :(得分:1)

这种方式更容易:

$env:

然后从任何单元格中输入公式:<code> Function AlarmDescriptions(Val As Integer) As String Dim alarmMsg As String Select Case Val Case 0 alarmMsg = "No Active Alarms" Case 1 alarmMsg = "Proofer Output Failure Safety" Case Else alarmMsg = "Main Drive Overload" End Select AlarmDescriptions = alarmMsg End Function Public Function Msg(Val As Integer) As String Dim Timestamp As Date Timestamp = Now Msg = Now & " - " & Val & " - " & AlarmDescriptions(Val) End Function </code> 并且消息将显示在该单元格中