簡體   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