Error 'Type Mismatch' when attempting to use Application.WorksheetFunction.Index

daheefman

New Member
Joined
Jan 11, 2016
Messages
3
Hey there everyone

I have a spreadsheet with data in Range B10:P97.
I am attempting to create a single array of the two ranges B10:B97 and O10:O97.

I have read this previous thread heavily
http://www.mrexcel.com/forum/excel-questions/564473-transfer-multiple-ranges-one-array-2.html
but unfortunately I am still suffering from
Run-time Error '13'
Type Mismatch


My code is

Code:
Sub Test()
Dim vArr As Variant
vArr = Application.WorksheetFunction.Index(Cells, [row(10:97)], Array(2, 15))
End Sub

The error seems to be thrown due to the [row(10:97)] parameter. When replaced by a single row number there are no issues.

I am using Excel 2013.

Thank you very much for the help.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to the Forum!

This works for me:

vArr = Application.Index(Cells, [row(10:97)], Array(2, 15))
 
Upvote 0
Welcome to the Forum!

This works for me:

vArr = Application.Index(Cells, [row(10:97)], Array(2, 15))

Wow this is working for me too, thank you!
Would you be able to explain when .WeeksheetFunction would be used? In other examples I have seen it done in other examples.

Thanks again!
 
Upvote 0
Wow this is working for me too, thank you!
Would you be able to explain when .WeeksheetFunction would be used?

This thread may be helpful in general terms: http://www.mrexcel.com/forum/excel-...ication-vs-application-worksheetfunction.html

In your specific example:

1. In Excel, you can array-enter a formula like this:

=INDEX(1:100, ROW(10:97), {2,15})

2. Pass it to VBA variant like this and you will get a Type Mismatch error:

vArr = WorksheetFunction.Index(Range("1:100"), [row(10:97)], Array(2, 15))

3. But use the Application object instead, and it will work:

vArr = Application.Index(Range("1:100"), [row(10:97)], Array(2, 15))

This looks like an Excel quirk to me. Something gets "lost in translation" using WorksheetFunction.

Perhaps someone else can provide a more technical explanation?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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