Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 57593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:42:56+00:00 2026-05-10T17:42:56+00:00

What function can I use in Excel VBA to slice an array?

  • 0

What function can I use in Excel VBA to slice an array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:42:56+00:00Added an answer on May 10, 2026 at 5:42 pm

    Application.WorksheetFunction.Index(array, row, column)

    If you specify a zero value for row or column, then you’ll get the entire column or row that is specified.

    Example:

    Application.WorksheetFunction.Index(array, 0, 3)

    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.Index can handle if you’re using a newer version of Excel. If array has 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:

    Public Function GetArraySlice2D(Sarray As Variant, Stype As String, Sindex As Integer, Sstart As Integer, Sfinish As Integer) As Variant  ' this function returns a slice of an array, Stype is either row or column ' Sstart is beginning of slice, Sfinish is end of slice (Sfinish = 0 means entire ' row or column is taken), Sindex is the row or column to be sliced ' (NOTE: 1 is always the first row or first column) ' an Sindex value of 0 means that the array is one dimensional 3/20/09 ljr  Dim vtemp() As Variant Dim i As Integer  On Err GoTo ErrHandler  Select Case Sindex     Case 0         If Sfinish - Sstart = UBound(Sarray) - LBound(Sarray) Then             vtemp = Sarray         Else             ReDim vtemp(1 To Sfinish - Sstart + 1)             For i = 1 To Sfinish - Sstart + 1                 vtemp(i) = Sarray(i + Sstart - 1)             Next i         End If     Case Else         Select Case Stype             Case 'row'                 If Sfinish = 0 Or (Sstart = LBound(Sarray, 2) And Sfinish = UBound(Sarray, 2)) Then                     vtemp = Application.WorksheetFunction.Index(Sarray, Sindex, 0)                 Else                     ReDim vtemp(1 To Sfinish - Sstart + 1)                     For i = 1 To Sfinish - Sstart + 1                         vtemp(i) = Sarray(Sindex, i + Sstart - 1)                     Next i                 End If             Case 'column'                 If Sfinish = 0 Or (Sstart = LBound(Sarray, 1) And Sfinish = UBound(Sarray, 1)) Then                     vtemp = Application.WorksheetFunction.Index(Sarray, 0, Sindex)                 Else                     ReDim vtemp(1 To Sfinish - Sstart + 1)                     For i = 1 To Sfinish - Sstart + 1                         vtemp(i) = Sarray(i + Sstart - 1, Sindex)                     Next i                 End If         End Select End Select GetArraySlice2D = vtemp Exit Function  ErrHandler:     Dim M As Integer     M = MsgBox('Bad Array Input', vbOKOnly, 'GetArraySlice2D')  End Function 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Try ( echo 1; echo 2 ) > file.txt That… May 11, 2026 at 10:31 am
  • added an answer Preprocessor will offer a more robust and generic solution. Macros… May 11, 2026 at 10:31 am
  • added an answer I put together a fairly lengthy answer to a similar… May 11, 2026 at 10:31 am

Related Questions

What function can I use in Excel VBA to slice an array?
I understand what are lambda functions in Python, but I can't find what is
Can anyone provide a clear explanation / example of what these functions do, and
What function will let us know whether a date in VBA is in DST
This question is simple. What function would I use in a PHP script to
I'm used to sampling C-based apps, which every few milliseconds sees what function stack
What delphi function asserts that an object is not nil?
So I have something like this: var xmlStatement:String = xmlObject.node[3].@thisValue; What mystery function do
What JavaScript keywords (function names, variables, etc) are reserved?
What is the function of the namespace here? I would think in this simple

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.