VBA Check name in Range If not Perform action - Need help

jmazorra

Well-known Member
Joined
Mar 19, 2011
Messages
715
Hello folks:

Here is what I am trying to do. If a name is entered in cboRepName combo box, I want to check if the name matches the list of names in the named range "Names" found in sheet repInformation. If the name is not found, then perform tasks.

Here is what I have so far, of course is not working, but I think I am close.

Code:
Private Sub cboRepName_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim repName As String
Dim nRange As Range

Set WS = Worksheets("repInformation")
Set nRange = WS.Range("Names")

repName = Me.cboRepName.Value

If repName <> nRange Then
   
    Me.lblLocation.Enabled = True
    Me.cboRepName.Enabled = True
    
        End If
        
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Your mistake is in the if statement :

Code:
Private Sub cboRepName_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
Dim repName As String
Dim nRange As Range

Set WS = Worksheets("repInformation")
Set nRange = WS.Range("Names")

repName = Me.cboRepName.Value

If IsError(Application.Match(repName, nRange, 0)) Then
   Me.lblLocation.Enabled = True
   Me.cboRepName.Enabled = True
End If

End Sub

ZAX
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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