Worksheet_Change as Data Validation

m1ngle

New Member
Joined
Mar 17, 2015
Messages
16
I am trying to use worksheet_change as a data validation check. I want to insure values pasted into cells range a1:a3000 match a list of values from a list. I'm afraid I'm lost and don't know how to proceed.
Here is what I have so far
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rang As Range
Set Rang = Worksheets("DATA INPUT SHEET").Range("A1:A3000")
If Intersect(Target, Rang) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub</code>What I want to add would be along the lines of:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">If Target.Value <> Worksheets("Worksheet 2".Range("B2:B7") Then
MsgBox
"The value you entered is not valid"</code>Does anyone have any suggestions?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rang As Range
    Set Rang = Worksheets("DATA INPUT SHEET").Range("A1:A3000")
    If Not Intersect(Target, Rang) Is Nothing Then
        For Each c In Target
            Set fnd = Worksheets("Worksheet 2").Range("B2:B7").Find(c.Value, lookat:=xlWhole, LookIn:=xlValues, MatchCase:=False)
            If fnd Is Nothing Then
                MsgBox "The value you entered at " & c.Address & " is not valid"
            End If
        Next
    End If
End Sub
 
Upvote 0
Thanks so much. It was extremely innovative. Is there any way to not generate the error when the contents are deleted?

Try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Rang As Range
    Set Rang = Worksheets("DATA INPUT SHEET").Range("A1:A3000")
    If Not Intersect(Target, Rang) Is Nothing Then
        For Each c In Target
            Set fnd = Worksheets("Worksheet 2").Range("B2:B7").Find(c.Value, lookat:=xlWhole, LookIn:=xlValues, MatchCase:=False)
            If fnd Is Nothing Then
                MsgBox "The value you entered at " & c.Address & " is not valid"
            End If
        Next
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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