why is match not working in this case?

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
393
Office Version
  1. 365
Platform
  1. Windows
Gurus,
below code returns "unable to get the match property of the worksheetfunction class"
VBA Code:
for each tb1 in sheets("abc").listobjects
  a= worksheetfunction.match( "SS", tb1.headerrowrange,0)
next tb1

Thanks!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
when you don't have a match with worksheetfunction, you get an error.
Use application, that 'll result in a number, in case of a match or an errorvalue, but want stop your macro
VBA Code:
For Each tb1 In Sheets("abc").ListObjects
     a = Application.Match("SS", tb1.HeaderRowRange, 0)
     If IsNumeric(a) Then MsgBox "found"
Next tb1
 
Upvote 0
Solution
I am probably in the minority but I like to "dim a as long" so I do it this way.
VBA Code:
    Dim a As Long
    For Each tb1 In Sheets("abc").ListObjects
         a = Application.IfError(Application.Match("SS", tb1.HeaderRowRange, 0), 0)
         If a <> 0 Then MsgBox "found"
    Next tb1
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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