WorksheetFunction.Match trouble

KG Old Wolf

Board Regular
Joined
Sep 20, 2009
Messages
65
All,

The MAX function works fine but the MATCH does not. I am trying to obtain a column number. MATCH works with hard code but I need to use a variable. As soon as I attempt to make the range a variable, it fails

Dim myRange As Range
myRange = Worksheets("tbl_Allocations").Range("E6:P6")
'
ary_Max_Value = WorksheetFunction.Max(ary_Work_Area)
ary_c_count = WorksheetFunction.Match(ary_Max_Value, Range("E6:P6"), 0)

It fails if if I use:
ary_c_count = WorksheetFunction.Match(ary_Max_Value, Range("myRange"), 0)


I cannot see what I am doing wrong... any ideas?

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
What did you dim ary_c_count as? Also, where exactly is it erroring, and what error are you receiving?
 
Upvote 0
Why are you using the worksheet function MATCH as opposed to the VBA function FIND?

Also RANGE is an object and therefore requires the SET keyword:

Set myRange = Worksheets("tbl_Allocations").Range("E6:P6")

and then refer to this range as a range

The MAX function shouldn't work because you haven't assigned a range to ary_Work_Area
 
Last edited:
Upvote 0
the "set" was made earlier in the code.

I solved the problem... it is an array I was inspecting....

I tried many variations including going right at the array but that didn't work (which didn't make any sense but I moved on). HOWEVER, the following works because I placed () after the array name.
It is odd that the "MAX" function didn't require the parentheses....


ary_Max_Value = WorksheetFunction.Max(ary_Work_Area)
'
ary_c_count = WorksheetFunction.Match(ary_Max_Value, ary_Work_Area(), 0)


Thanks for your prompt responses... and I hope this helps others
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,085
Members
452,378
Latest member
Hoodzy01

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