VBA message box with and IF AND statement

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
365
I would like to have message pop up when a condition is met between 2 cells. I need something like this. Thanks

Private Sub Worksheet_calculate()
If Range("K23").Value > 500 And ("E23") = "KIT" Then
MsgBox ("this is a test")
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try:
Code:
[COLOR=#333333]Private Sub Worksheet_calculate()[/COLOR]
[COLOR=#333333]    If Range("K23").Value > 500 And [/COLOR][COLOR=#ff0000]Range[/COLOR][COLOR=#333333]("E23") = "KIT" Then[/COLOR]
[COLOR=#333333]        MsgBox "this is a test"
    End If
End Sub[/COLOR]
 
Upvote 0
Is this what you mean?
Code:
Private Sub Worksheet_calculate()
 If Range("K23").Value > 500 And Range("E23").Value = "KIT" Then MsgBox "this is a test"
End Sub
 
Upvote 0
Yes thus works. So now I want to use the below code to work with a range of cells, not just one. For example, I want the warning to work for cell "C23" down to the last cell with data. If it matters, we populate the first row with data and then copy the first row down let's say 20 rows and then we modify the data in those rows.

Private Sub Worksheet_calculate()
If Range("C23").Value = "SL10" Then MsgBox "USE CONTINUOUS CHAIN"
End Sub
 
Upvote 0
Code:
Private Sub Worksheet_calculate()
 Dim c As Range
  For Each c In Range("C23:C" & Cells(Rows.Count, 3).End(3).Row)
   If c.Value = "SL10" Then MsgBox "USE CONTINUOUS CHAIN" & " at  " & c.Address(0, 0)
  Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,579
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top