Results 1 to 1 of 1

Store Found values directly in array

Threaded View

cgkmal Store Found values directly... 06-15-2011, 04:41 PM
  1. #1
    Forum Contributor
    Join Date
    06-07-2011
    Location
    Hnd
    MS-Off Ver
    Excel 2010
    Posts
    161

    Store Found values directly in array

    Hi to all,

    Some help please.

    I normally use a loop with "Find" method to search for some word and store in an Array all its positions within a range. Something like this:

    Sub Find()
    Dim MyArray(), CurrentValueAddress As String, b As Interior, Count As Integer
            
    CurrentValueAddress = "A1" : Count = 5
    ReDim MyArray(1 To Count)
    
    For b = 1 To Count 
      CurrentValueAddress = Columns("A:C").Find(What:= _
                        "String", After:=Range(CurrentValueAddress), LookIn:= _
                        xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
                        xlNext, MatchCase:=False).Address
                        
        MyArray(b) = CurrentValueAddress
    Next
    End Sub
    When I record a macro--> Ctrl+F-->entering a "string" to search and--> clicking "Search all" Excel finds all ocurrences and respective positions in a range.

    I was wondering if somebody knows how to do with VBA a "Search all" and store the result in an Array directly avoiding use a loop for this.

    I remember I saw time ago in some place that somebody do something similar using collections or areas, I'm not sure, but it looks that stores values in Array without loop.

    Any help would be very appreciated.

    Regards
    Last edited by cgkmal; 06-15-2011 at 04:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1