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).
Also if I hit ok i need to register "true" to another cell or if i hit cancel insert to a cell FALSE
My FIRST vba code so please show some understanding, Thanks a lot in advance.
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 :
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.