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:

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,950
Office Version
  1. 365
Platform
  1. Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,122,969
Messages
5,599,104
Members
414,287
Latest member
Rbwester

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
Top