简体   繁体   English

在Excel中显示消息框

[英]Display message box in excel

I need to compare two date columns in excel(vba). 我需要比较excel(vba)中的两个日期列。 If the cell values are equal, a message box has to be displayed with "TARGET ACHIEVED", "YES" or "NO" option. 如果单元格值相等,则必须显示一个带有“ TARGET ACHIEVED”,“ YES”或“ NO”选项的消息框。 Based on the value selected, 2nd column cell color has to be changed - YES - orange - NO - blue 根据所选的值,必须更改第二列单元格的颜色-是-橙色-否-蓝色

Following code will do it. 下面的代码可以做到。

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

You can get more Excel colour codes here . 您可以在此处获得更多的Excel颜色代码。

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

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