VBA message box with and IF AND statement

Shadkng

Active Member
Joined
Oct 11, 2018
Messages
370
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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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