+ Reply to Thread
Results 1 to 13 of 13

Search column items in multiple sheets

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Search column items in multiple sheets

    Hello everyone
    I have some items in column A in sheet1 ..and I intend to search for each item in the other sheets
    The search will be through the used range of the sheet and return the value in the first column of the searched sheets
    I have the following code that works well for small amounts of data but in real file it is very very slow so I am searching for a faster way
    Please Login or Register  to view this content.
    * The issue is posted here too
    http://www.eileenslounge.com/viewtopic.php?f=30&t=29498
    Attached Files Attached Files
    Last edited by YasserKhalil; 03-23-2018 at 03:23 AM.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    I have changed the UDF to that form
    Please Login or Register  to view this content.
    But I don't know which is faster :using loops as in the first post or using Index and match as in the second post ..
    Can you guide me please?

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search column items in multiple sheets

    Quote Originally Posted by YasserKhalil View Post
    But I don't know which is faster :using loops as in the first post or using Index and match as in the second post ..
    Can you guide me please?
    See
    https://www.excelforum.com/excel-pro...ml#post4857979

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    Thanks a lot Mr. Jindon
    So you mean looping through columns using Index and Match is faster than looping through the arrays using Index and Match ?
    Can you help me improving the code?

  5. #5
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Search column items in multiple sheets

    Could this be a little faster ?

    Code on ThisWorkbook Module :
    Please Login or Register  to view this content.
    Code on Standard Module :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    That's great and fascinating Mr. Karedog
    Thank you very very much

    I am trying to apply it on the original file now .. Some cells has NA error so I encountered an error at this line
    Please Login or Register  to view this content.
    How to avoid error cells ? Would I add a line If Not Iserror(a(i, j)) before that line or that may slow down the process?

  7. #7
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Search column items in multiple sheets

    You are welcome.
    I don't think so, it should be nothing (IsError is a builtin VBA function, it should be fast), and beside, the RefreshZ is only called once when refreshing the collection, so it is not depending on how many items on Sheet1!A:A

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    Really amazing. I didn't believe it can be done in that speed
    You are amazing my friend

    * One last question as for the UDF posted in the first post and the UDF posted in the second post : which is faster ...? or is there another udf that searches 2d array faster than these UDFs

    * The main problem solved but I like to have a solution for that part too

  9. #9
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Search column items in multiple sheets

    Why don't you try to measure it by yourself ?
    Just my guess, if number of rows of the array is little, the For..Loop will win, but if many, probably the Application.Match wins (since there is overhead calling a worksheet function).

    BTW, if it is possible to use an array formula, then my code can be written as an UDF too (you need to delete all my previous code first) :
    Please Login or Register  to view this content.
    Usage : Array formula on Sheet1!B2:B5 :
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    or even just :
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    but you must manually recalc the sheet, or insert the Application.Volatile to the UDF

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    Thanks a lot my friend
    I didn't mean the main issue .. It was solved by you completely and it was amazing solution .. I didn't mean to have a solution by converting your code to UDF

    * I am talking about searching in 2D array ..
    Here's the code
    Please Login or Register  to view this content.
    Is that UDF for searching the UDF is faster or not (I would not test .. because I need to know from you the better case) ..
    Can this udf that would search 2D arrays ..can we use collections if faster?

  11. #11
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Search column items in multiple sheets

    Please Login or Register  to view this content.
    Well well ...
    Here I have set up the test code for both of your UDF (using For..Loop and Application.Match)
    Just run the code, and examine the result (I still don't understand why everybody is so afraid of looping)
    You can also change number of rows by changing the line with red color, for example from 100 to 10000

    As for collection, no, collection won't make the UDF faster if it is used in your SearchIn2DArray() UDF, since this UDF is called as any time as number of items on Sheet1!A:A. In fact, it will be slower, since array operation (a simple variable) is much faster than collection (an object).

  12. #12
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Search column items in multiple sheets

    Perfect my friend
    That's exactly what I was seeking for .. I was seeking for such a demonstration .. Now I would support loops I won't be afraid of loops inside arrays anymore
    Thanks a lot for great and incredible help
    Best and kind regards

  13. #13
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Search column items in multiple sheets

    You are welcome, thanks for marking the thread as solved and rep.points.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Search for a column across multiple sheets and copy them in 1st sheet.
    By gauti14 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-20-2017, 04:41 PM
  2. [SOLVED] Basic User list items , search, Edit from three sheets
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-15-2014, 06:52 AM
  3. [SOLVED] Need to count items in column that match multiple data items
    By bclucas55 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-27-2014, 10:03 AM
  4. [SOLVED] Search within a column and repeat the search until all items are found
    By RANDY LIPOSKY in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-09-2014, 10:23 AM
  5. Replies: 0
    Last Post: 10-15-2012, 12:12 PM
  6. Search column for three items
    By erblaze in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 06-08-2011, 02:48 PM
  7. Replies: 3
    Last Post: 01-21-2010, 06:58 AM

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