繁体   English   中英

在Excel中显示消息框

[英]Display message box in excel

我需要比较excel(vba)中的两个日期列。 如果单元格值相等,则必须显示一个带有“ TARGET ACHIEVED”,“ YES”或“ NO”选项的消息框。 根据所选的值,必须更改第二列单元格的颜色-是-橙色-否-蓝色

下面的代码可以做到。

Dim Date1 As String
Dim Date2 As String
Dim msgResult As VbMsgBoxResult

Date1 = ThisWorkbook.Sheets(1).Cells(1)
Date2 = ThisWorkbook.Sheets(1).Cells(2)

If IsDate(Date1) And IsDate(Date2) Then
    If CDate(Date1) = CDate(Date2) Then
        msgResult = MsgBox("TARGET ACHIEVED", vbYesNo)

        If vbYes = msgResult Then
            ' code for Yes handling
            ThisWorkbook.Sheets(1).Cells(1).Interior.ColorIndex = 46 'orange
        Else
            ' code for NO handling
            ThisWorkbook.Sheets(1).Cells(1).Interior.ColorIndex = 5 'blue color
        End If
    End If
End If

您可以在此处获得更多的Excel颜色代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM