VBA - index cell in selection - worksheetfunction.index(selection,cell)

i_excel

Board Regular
Joined
Jun 4, 2015
Messages
113
Hi

The following code doesn't work

Code:
Sub Index()
Dim Cell as Range
For Each Cell In Selection
    MsgBox WorksheetFunction.Index(Selection, Cell)
Next Cell

Does anyone know why that is?

Any help would be greatly appreciated.

i_excel
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
What exactly are you trying to accomplish?

Also, NEVER use reserved words (i.e. names of functions, properties, objects, methods) for the name of variables or procedures!
You named your procedure INDEX.
So now whenever you use INDEX in your code, Excel might get confused, not sure if you are referring to the native INDEX function or your custom INDEX procedure. This can let to unexpected behavior.

Always use unique names. I often preface with "My", i.e. Sub MyIndex()
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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