+ Reply to Thread
Results 1 to 8 of 8

How does excels find function actually "find" values?

Hybrid View

111StepsAhead How does excels find function... 12-15-2011, 10:40 AM
StephenR Re: How does excels find... 12-15-2011, 10:45 AM
dilipandey Re: How does excels find... 12-15-2011, 10:47 AM
111StepsAhead Re: How does excels find... 12-15-2011, 11:33 AM
111StepsAhead Re: How does excels find... 12-15-2011, 11:39 AM
StephenR Re: How does excels find... 12-15-2011, 11:42 AM
111StepsAhead Re: How does excels find... 12-15-2011, 11:51 AM
StephenR Re: How does excels find... 12-15-2011, 11:53 AM
  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    How does excels find function actually "find" values?

    I have a 50,000 item list of serial numbers. What I notice is when I do a search for 45678 and then 40000 it takes a lot longer then the reverse process. This seems to slow my macro down a lot. I wanted to confirm with somebody who might know more about excels find function that this is the case.

    And is there a better way? My first thought was to add starting points to search at since the serial numbers are in a general order but do skip a few spots.

    Any thoughts are appreciated. Thanks.
    Last edited by 111StepsAhead; 12-15-2011 at 11:40 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How does excels find function actually "find" values?

    Find is generally reckoned to be pretty fast. It might depend on search order though - can you post your code?

  3. #3
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How does excels find function actually "find" values?

    I believe Excel finds starting from left to right and then down and repeats it till the value get found out.

    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

  4. #4
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How does excels find function actually "find" values?

    Sub Main3()
        Dim x As Long
        Dim y As Long
        Dim LastRow As Long
        Dim ws As Worksheet
        
        Dim tempSource As String
    
        Dim tempSourceRow As Long
        Dim tempDestRow As Long
        
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name <> "Main" And ws.Name <> "Master" Then
                ws.Activate
                If Range("Y1").Value = "serial_access_name" Then
                    LastRow = Cells(Rows.Count, "Y").End(xlUp).Row
                    For x = 2 To LastRow
                        '1) Get the serial_access_name off of the worksheet.
                            Range("Y" & x).Select
                            tempSource = ActiveCell.Value
                            tempSourceRow = ActiveCell.Row
                        '2) Find the spot in the database page.
                            Worksheets("Master").Activate
                            tempDestRow = Cells(Rows.Count, "C").End(xlUp).Row
                            Cells(1, 3).Select
                            Cells.Find(What:=tempSource, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
                            
                        '3) Move the data from the worksheet to the database.
                            'ws.Activate
                            'Sheets(ws).Range("Y" & tempSourceRow).Select
                            ws.Activate
                            Range("Y" & tempSourceRow).Select
                            'ActiveCell.Offset(0, 1).Activate
                            Range("Z" & tempSourceRow, "AD" & tempSourceRow).Copy Destination:=Sheets("Master").Range("E" & tempDestRow)
                        '4) Check next serial_access_name until all are checked.
                    Next x
                End If
            End If
        Next ws
    End Sub
    I am taking several sheets of data and moving them into one large sheet which originally I thought might be faster then multiple sheets. However, it seems I might be wrong about that idea.

  5. #5
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How does excels find function actually "find" values?

    I came across this thread while searching for a solution to this problem

    http://stackoverflow.com/questions/1...-binary-search

    Basically it looks like I should set up a binary search since I know the data is in order. I am going to close this thread but if anyone has ideas/thoughts I'd still like to hear them and will check back periodically. Thanks for your help dilipandey. You confirm what I was guessing to be true about the excel find.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How does excels find function actually "find" values?

    You could speed up your code a little by removing the Activates and Selects.

  7. #7
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: How does excels find function actually "find" values?

    You could speed up your code a little by removing the Activates and Selects.
    Excel threw an error when I used

    Sheets(ws).Range("Z" & tempSourceRow, "AD" & tempSourceRow).Copy Destination:=Sheets("Master").Range("E" & tempDestRow)
    Type mismatch to be exact so I just separately activated the correct sheet and then copied the data.

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: How does excels find function actually "find" values?

    ws.Range("Z" & tempSourceRow, "AD" & tempSourceRow).Copy Destination:=Sheets("Master").Range("E" & tempDestRow)

+ Reply to Thread

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