在Excel中显示消息框

我需要比较excel(vba)中的两个date列。 如果单元格值相等,则必须使用“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颜色代码。