worksheet function match a named range in VBA

juanbolas

New Member
Joined
Dec 3, 2014
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to write code that will check if the cell values have changed in a given range, and if so check if the value is in a list. If it´s not on the list it should open up a form to enter the new suppliers information.

I'm running into a problem trying to match the value entered in the cell to the list. the error i get is "Run-time error 1004: Unable to get the Match property of the WorksheetFunction class".

Code follows. Any help is appreciated.

VBA Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range) 'Excel VBA with more cells in the range.
If Not Intersect(Target, Range("Proveedores_Input")) Is Nothing Then
    If WorksheetFunction.Match(Target.Value, Sheets("Proveedores").Range("C5:C1000000"), 0) Then
'    If WorksheetFunction.Match(Target.Value, Sheets("Proveedores").Range("Proveedores_Lista"), 0) Then
        MsgBox Target.Value & " - Matched"
    End If
End If
End Sub
 

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.
WorksheetFunction.Match will return that error if it doesn't find a match.
I use
VBA Code:
myMatch = Application.Match(Target.Value, Sheets("Proveedores").Range("C5:C1000000"), 0)
If IsError(myMatch) Then
'   what to do if no match found
Else
'   what to do if there is a match
End If

myMatch has to be dimmed as variant

Beware that your code doesn't consider the possibility that more than one cell get changed
 
Upvote 0
Another option
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range) 'Excel VBA with more cells in the range.
    Dim rngResult As Range
    
    If Not Intersect(Target, Range("Proveedores_Input")) Is Nothing And Target.Cells.Count = 1 Then
        Set rngResult = Sheets("Proveedores").Range("C5:C1000000").Find(What:=Target.Value, LookAt:=xlWhole)
        
        If Not rngResult Is Nothing Then
            MsgBox Target.Value & " - Matched"
        Else
            MsgBox Target.Value & " - NOT Matched"
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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