VBA Popup Window by value

Watchdawg

Board Regular
Joined
Jan 21, 2015
Messages
84
Hello folks. Been searching but haven't found anything quite getting me what I need.
I have a spreadsheet with 2 tabs on it. First tab is titled "test list", this contains a short list of part numbers
Second tab is where the customer enters their data in cell A1. This is a part number. If that part number exists on tab 1, range A1:A21, I need it to pop up a message box warning them that they're moving the wrong product.

Is this even possible? I can't find something to point it to a range on a different tab.

Thanks in advance!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
It's a little vague but this should point you in the right direction.

Many ways to achieve your goal. Here is one way:

Open the code window of the 2nd sheet where the user enters a part number into A1 and past this code, ensuring you change the sheet 2 name accoridngly (you missed that sheet name out of your OP). Ive highlighted it in red below

Code:
Sub Check()
    Dim rList As Range
    Dim sPartNo As String
    
    
    Set rList = Sheets("test list").Range("A1:A21")
    
    sPartNo = Sheets("[B][COLOR=#ff0000]Sheet2[/COLOR][/B]").Range("A1") 'Change sheetname accordingly
    
    If rList.Find(sPartNo) Is Nothing Then
        'code to run if part no isn't in list
    Else
        MsgBox "You are moving the wrong product!", vbCritical, "Please Check"
        'Any other code to run if partno exists
    End If
    
    
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then Check
End Sub
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   Dim Fnd As Range
   
   If Target.CountLarge > 1 Then Exit Sub
   If Target = Range("A1") Then
      Set Fnd = Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Columns(1).Find(Target.Value, , , xlWhole, , , False, , False)
      If Not Fnd Is Nothing Then MsgBox "Wrong Product"
   End If
End Sub
Changing sheet name in red to suit
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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