Consulting

Results 1 to 5 of 5

Thread: Excel searching and VB

  1. #1
    VBAX Newbie
    Joined
    Jan 2005
    Posts
    2
    Location

    Excel searching and VB

    I'm currently developing some software that accepts a list of words from a file and then searches all matching excel files found in a given folder. The issue i've run into is that searching a large spreadsheet (A1-N64000) seems to progressively become slower. This particular problem can be duplicated by opening this large spreadsheet and searching for a term that is found on the 64000th row. When clicking "Find Next" the box that has the current cell updates quickly and then starts updating every 100 rows or so, eventually diminishing to about 20 rows. I've tried setting all excel properties (screen updating, calculation, alerts, hiding, etc...) but none of them seem to work. Does anyone have an efficient method of searching an excel workbook programmatically? I'm using XP with Office 2003.

    Thanks in advance.

  2. #2
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    If it's slow doing it with control F I can't see that there's anyway of speeding it up unfortunately. You could look into the text file structure of the file and see if all the cell data is unencrypted and intact. If so this may be an option...
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  3. #3
    VBAX Newbie
    Joined
    Jan 2005
    Posts
    2
    Location
    I've come to determine that the argument Lookin:=xlValues is what's causing it to hang...when I remove it, the speed is amazing, when I insert it, I start experiencing delays...the most I've waited is 40 minutes for a find to complete before killing excel...what is the correct find syntac when trying to find a value in both xlValues and xlFormulas...not in a macro though because I've read that the values defined for xlValues and xlFormulas might be different than those defined in VB6. Thanks for the reply though.

    btw...this is what I'm using:

    [vba]Set oUsedRange = oSheet.UsedRange
    Set oFoundResults = oUsedRange.Find(What:=searchTerm, _
    LookIn:=xlValues, MatchCase:=False, LookAt:=xlPart, _
    SearchOrder:=xlByRows, SearchDirection:=xlNext)[/vba]

    the bolded piece above is the key to this problem...

  4. #4
    VBAX Regular macleanb's Avatar
    Joined
    Feb 2005
    Location
    Essex
    Posts
    23
    Location
    Hi

    Not just to confuse you honest - I created a test spreadhseet with a jumble of "asdasd" type strings (rubbish - about 200 variations) and filled a spreadsheet A1:O65536 with this data. When I search this performance seems pretty linear and finding a string that was unique to the last row took ~ 4 seconds. I am suspecting that this is not a feature of search, but something a bit more environmental. SO I am thinking you should widen your search somewhat and perhaps take a look at the performance tab of task manager while you are doing this. I have a suspicion that you must be paging - as this fits the "performance cliff" you are falling off. Perhaps I have missed a salient step to recreate this issue - please let me know.

  5. #5
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi kl34i2,

    Just an FYI, I edited your post to use the VBA tags developed for this site by our very own Mark007. I also put in some line continuation characters so your text wrapped in the VBA tags.

    If you'd like to use them in future, just use (vba) VBA code here (/vba), where the brackets are replaced by [ and ].

    Cheers,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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