What function can I use in Excel VBA to slice an array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you specify a zero value for row or column, then you’ll get the entire column or row that is specified.
Example:
This will give you the entire 3rd column.
If you specify both row and column as non-zero, then you’ll get only the specific element. There is no easy way to get a smaller slice than a complete row or column.
Limitation: There is a limit to the array size that
WorksheetFunction.Indexcan handle if you’re using a newer version of Excel. Ifarrayhas more than 65,536 rows or 65,536 columns, then it throws a ‘Type mismatch’ error. If this is an issue for you, then see this more complicated answer which is not subject to the same limitation.Here’s the function I wrote to do all my 1D and 2D slicing: