Warning Message if Cells Match

austicks84

New Member
Joined
May 8, 2018
Messages
11
Hi i would like to have a warning message box pop up if i enter a value into a cell that matches a value from another range of cells.

The range of cells with preset values in it is P3:P10

If i enter a value in the range R3:AC10 that matches one of the values in the range P3:P10 i would like the warning message box to pop up.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Create Names as under
P3:P10 - "ChkRng"
R3:AC10 - "InputRng"
The code below presumes both ranges are in the same worksheet
Paste the following code in the worksheet module
You are good to go:)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rng As Range, Chk As Range
    Set Rng = Range("InputRng")
    Set Chk = Range("CheckRng")
    If Intersect(Target, Rng) Then
        Mtch = 0
        On Error Resume Next
        Mtch = WorksheetFunction.Match(Target.Value, Chk, 0)
        On Error GoTo 0
        If Mtch > 0 Then MsgBox ("Found")
    End If
End Sub
 
Last edited:
Upvote 0
I have just tried this, however, the error message box comes up if the value entered into the range R3:AC10 does not appear in the range P3:P10. I would like the error message to come up if the value entered does appear in the range P3:P10. Is there a way to do this using data validation?
 
Upvote 0
I have just tried this, however, the error message box comes up if the value entered into the range R3:AC10 does not appear in the range P3:P10. I would like the error message to come up if the value entered does appear in the range P3:P10. Is there a way to do this using data validation?
 
Upvote 0
I have just tried this, however, the error message box comes up if the value entered into the range R3:AC10 does not appear in the range P3:P10. I would like the error message to come up if the value entered does appear in the range P3:P10. Is there a way to do this using data validation?

I checked the code on dummy data b4 posting....it does throw up an alert only when the entered data is found in P3:P10....if not the code performs no action.
The code assumes that both the input range and the check range are on the same sheet
Please post a screenshot of your data.
 
Upvote 0
I have just tried this, however, the error message box comes up if the value entered into the range R3:AC10 does not appear in the range P3:P10. I would like the error message to come up if the value entered does appear in the range P3:P10. Is there a way to do this using data validation?

Name the ranges as suggested.
Select InputRng with cell R3 active
Do Data>Validation>Formula in the Settings tab
In the formula box enter:
=ISNA(MATCH(R3,CheckRng,0))
Put a custom error msg in the Error msg tab.
You are done.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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