简体   繁体   English

弹出消息框

[英]Message box pop up

I need to build a code to give me a pop up message if the value of a cell (Price) is bigger than another cell (Target). 如果一个单元格(价格)的值大于另一个单元格(目标)的值,我需要构建一个代码以给我弹出消息。 If PRICE > TARGET then pop up a window (ideally with sound). 如果PRICE> TARGET,则弹出一个窗口 (理想情况下带有声音)。

Also if I hit ok i need to register "true" to another cell or if i hit cancel insert to a cell FALSE 另外,如果我打了好 ,我需要注册“真”到另一个单元格,或者如果我打取消插入到细胞FALSE

My FIRST vba code so please show some understanding, Thanks a lot in advance. 我的第一个vba代码,所以请表现出一些理解,在此先多谢。

Private Sub CommandButton1_Click()

Sub userinput()

Dim ireply As Integer

If Range("C6").Value > Range("E6").Value Then

ireply = MsgBox(prompt:="Price" & Range("F6").Value & " Reached target. Stop tracking ?", Buttons:=vbYesNoCancel, Title:="Tracking")

If ireply = vbYes Then

Range("B6").Value = "TRUE"

ElseIf ireply = vbNo Then

Range("B6").Value = "FALSE"

End Ifs

If Range("C7").Value > Range("E7") Then

End If

If Range("C8").Value > Range("E8") Then

End If

Exit Sub

End Sub

To make this possible directly when you input data into Excel, you'll need to place this into the sheet module of the sheet that you want it to work on : 为了在将数据输入到Excel中时直接实现此目的,您需要将其放置在要对其进行处理的工作表的工作表模块中:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim iReply As Integer

If Target.Count > 1 Then Exit Sub

If Application.Intersect(Target, Columns(3)) Is Nothing Then
Else
    If Range("C" & Target.Row).Value > Range("E" & Target.Row).Value Then
        Beep
        iReply = MsgBox("Price" & Range("F" & Target.Row).Value & " Reached target. Stop tracking ?", vbOKCancel + vbCritical, "Tracking")
        If iReply <> vbCancel Then
            Range("B" & Target.Row).Value = "TRUE"
        Else
            Range("B" & Target.Row).Value = "FALSE"
        End If
    Else
    End If
End If

End Sub

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

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