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

  • SEARCH
  • Home
  • 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 6239417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:23:19+00:00 2026-05-24T11:23:19+00:00

I have an array prLst that is a list of integers. The integers are

  • 0

I have an array prLst that is a list of integers. The integers are not sorted, because their position in the array represents a particular column on a spreadsheet. I want to know how I find a particular integer in the array, and return its index.

There does not seem to be any resource on showing me how without turning the array into a range on the worksheet. This seems a bit complicated. Is this just not possible with VBA?

  • 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. Editorial Team
    Editorial Team
    2026-05-24T11:23:19+00:00Added an answer on May 24, 2026 at 11:23 am
    Dim pos, arr, val
    
    arr=Array(1,2,4,5)
    val = 4
    
    pos=Application.Match(val, arr, False)
    
    if not iserror(pos) then
       Msgbox val & " is at position " & pos
    else
       Msgbox val & " not found!"
    end if
    

    Updated to show using Match (with .Index) to find a value in a dimension of a two-dimensional array:

    Dim arr(1 To 10, 1 To 2)
    Dim x
    
    For x = 1 To 10
        arr(x, 1) = x
        arr(x, 2) = 11 - x
    Next x
    
    Debug.Print Application.Match(3, Application.Index(arr, 0, 1), 0)
    Debug.Print Application.Match(3, Application.Index(arr, 0, 2), 0)
    

    EDIT: it’s worth illustrating here what @ARich pointed out in the comments – that using Index() to slice an array has horrible performance if you’re doing it in a loop.

    In testing (code below) the Index() approach is almost 2000-fold slower than using a nested loop.

    Sub PerfTest()
    
        Const VAL_TO_FIND As String = "R1800:C8"
        Dim a(1 To 2000, 1 To 10)
        Dim r As Long, c As Long, t
    
        For r = 1 To 2000
            For c = 1 To 10
                a(r, c) = "R" & r & ":C" & c
            Next c
        Next r
    
        t = Timer
        Debug.Print FindLoop(a, VAL_TO_FIND), Timer - t
        ' >> 0.00781 sec
    
         t = Timer
        Debug.Print FindIndex(a, VAL_TO_FIND), Timer - t
        ' >> 14.18 sec
    
    End Sub
    
    Function FindLoop(arr, val) As Boolean
        Dim r As Long, c As Long
        For r = 1 To UBound(arr, 1)
        For c = 1 To UBound(arr, 2)
            If arr(r, c) = val Then
                FindLoop = True
                Exit Function
            End If
        Next c
        Next r
    End Function
    
    Function FindIndex(arr, val)
        Dim r As Long
        For r = 1 To UBound(arr, 1)
            If Not IsError(Application.Match(val, Application.Index(arr, r, 0), 0)) Then
                FindIndex = True
                Exit Function
            End If
        Next r
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have array that need to sort by their appearance, as they are written
i have array like below which is sorted by array_count_values function, Array ( [Session
I have array of class Person in ViewModel and I want to show their
I have array that element is hash a = [{:history_date=>15/07/10}, {:open_price=>7.90}] I want to
I have array that looks like this, Array ( [email_address] => Array ( [0]
I have array with alphanumeric key values..While filling array on particular condition I have
I have array of Objects (let say that class name is Snap) Snap. Is
I have array d, I want array d2 The rows do not have the
I have a two dimensional array that I need to load data into. I
Suppose I have array of points.I want to draw the route of that points

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.