Check Input Box Variable against named Range. If Duplicate Then Exit Sub.

Falko26

Board Regular
Joined
Oct 13, 2021
Messages
89
Office Version
  1. 365
Platform
  1. Windows
All,

I have a Input Box Macro that adds names to a table. The column of the table is a named range "CrewDescriptions". I'm trying to check my input box variable against the Named Range "CrewDescriptions" for any duplicates and if so End Sub before it try's to enter the duplicate information.

VBA Code:
'Crewat New Crew
Sub BLC_NewCrew()
 
    'declare variable to hold value returned by InputBox
    Dim myInputBoxVariable As String
   
        'Create InputBox, and assign value returned by InputBox function to variable
    myInputBoxVariable = InputBox(Prompt:="New Crew Name:", Title:="Excel InputBox", Default:="-")
    If myInputBoxVariable = "" Then Exit Sub
   
    ' If myInputBoxVariable = a value that already exists in named range "CrewDescriptions" Then Exit Sub
   
    ' Rest of Code

Any Ideas?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It sounds like CrewDescriptions is a single column? In which case, try:

If IsNumeric(Application.Match(myInputBoxVariable, Range("CrewDescriptions"), 0)) Then Exit Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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