Using Index from VBA

jmbob666

New Member
Joined
Apr 22, 2011
Messages
4
I recently discovered the power of the Index function. It would be very helpful if I could only get it to work from VBA. For example:

Dim rYD as range
Set rYD = Range("C3:F10")
Data = Application.WorksheetFunction.Index(rYD, 1, 4)

Will return the value of what is in row 1, column 4 of range rYD, IE the value of F3. Not a problem. I on the other hand want to return the entire 4th column of data, as shown below:

Dim rYD as range
dim Data as range
Set rYD = Range("C3:F10")
Data = Application.WorksheetFunction.Index(rYD, , 4)

Unfortunately you get "Compile Error: Argument not Optional" when you run the macro. In a spreadsheet I can get the column if I array-enter the formula. Does anyone know how to get Index to put the data into a range variable?
 
Attention: I just found out that application index comes with a 65,537 size limit! Like in the good old days! Probably kept for compatibility only.

So, not a good generic solution. Better stay away from this unless for known small volumes unlikely to grow ever.
Better to use classic programming with loops & arrays. It is seems faster & much safer.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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