+ Reply to Thread
Results 1 to 7 of 7

.Find method usage on Time Values advice?

  1. #1
    Registered User
    Join Date
    08-08-2020
    Location
    Boston
    MS-Off Ver
    2019
    Posts
    33

    .Find method usage on Time Values advice?

    In a recent post, I was asking for advice about the fastest method to find values in a range using VBA, and came across sites that indicated the Range.Find method was hundreds of times faster than looping. So I gave it a go, and it works fine for me using the below code on integers. It does not work on time however, which is what I do need. There seems to be scant data on using this method for searching times, and some data regarding dates. Does anyone have any thoughts on this?

    The attached workbook has the below code and data in Sheet 1 as per the screen shot for testing.

    If you modify the code below from ".Range("f6:f10")" to ".Range("c6:c10"), and "myRangeTimes" to "myRangeIntegers", then you will be able to witness the Find method working with the corresponding integer values 1-5 in Sheet1. Using this same code on the time values as is shown below, returns the wrong result from the Find, setting the user entry "12:00:00 AM" cell interior color with the result from "10:00:00 AM" in the myRangeTimes range. I suspected the format had something to do with this, so I copied and pasted the user input cells to the myRangeTimes range to ensure there was no differences, but the problem persists.


    Please Login or Register  to view this content.
    Thanks in advance for any advice folks,
    Frank
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,977

    Re: .Find method usage on Time Values advice?

    I have found it helps to search for a string formatted the same way as the time in the cells you are searching. Try this. I've tested it.

    Please Login or Register  to view this content.

  3. #3
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: .Find method usage on Time Values advice?

    well this is pretty quirky, no doubt. see here:

    https://www.ozgrid.com/VBA/find-dates.htm

    the range cell is being read like numbers. furthermore, you have no args in your method. this should never be:
    Please Login or Register  to view this content.
    but rather it should be, at the very least:
    Please Login or Register  to view this content.
    then, you should test all of these:

    https://docs.microsoft.com/en-us/off...l.xlfindlookin

    this gives nothing:
    Please Login or Register  to view this content.
    this also gives nothing:
    Please Login or Register  to view this content.
    however, this DOES give something:
    Please Login or Register  to view this content.
    and so does this:
    Please Login or Register  to view this content.
    trial and error my friend. test, test, test. with software running rampant all over the world, WHO KNOWS? LOL.
    Attached Images Attached Images

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,787

    Re: .Find method usage on Time Values advice?

    you have no args in your method. this should never be:
    You don't need to put the name of the argument.

  5. #5
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: .Find method usage on Time Values advice?

    Quote Originally Posted by Fluff13 View Post
    You don't need to put the name of the argument.
    probably not. but everyone I've seen use it, does it.

  6. #6
    Registered User
    Join Date
    08-08-2020
    Location
    Boston
    MS-Off Ver
    2019
    Posts
    33

    Re: .Find method usage on Time Values advice?

    I think I've learned something here from both of you guys 6StringJazzer and vba_php on this one, thanks to both of you. 6StringJazzer you helped on a previous hurdle I ran into, thanks so much for help here too, the tested code worked just fine. vba_php, you mention that it was quirky. I imagine what is quirky for yourself and others at your level is a good bit more of a pain in the butt for coders at my level. I think part of the problem is that I think (in addition to be a relative beginner at vba) is that I have expectations of things not being quirky, or at least somewhat logical and obvious most of the time. I did try and test some arguments but gave up thinking there should be some documentation of the requirements for using Find on time, but, well ... maybe understanding different methods of solving problems is my big next lesson in vba as you suggest : )
    thanks folks,
    Frank
    Last edited by Frank Nunez; 11-29-2020 at 06:53 PM.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,454

    Re: .Find method usage on Time Values advice?

    @Frank Nunez: trust me, it doesn't always get easier. I DID try most of the arguments to .Find with no success. I put several Debug statements in the code at various points and still didn't find the solution. So, thanks to 6SJ and vba_php for putting ME out of my misery
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Advice - Method to use in transferring data from one workbook to another
    By CraigsWorld in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-24-2018, 12:57 AM
  2. Finding the last row on a worksheet - advice on best method
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2014, 09:10 PM
  3. Run-time error 91 using cells.find method
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2012, 06:40 AM
  4. Sortin method advice please
    By Zipadeedoodaa in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2006, 05:00 PM
  5. [SOLVED] Is there a method to find distinct values in a column
    By Ivan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-22-2005, 12:55 PM
  6. [SOLVED] Advice on method
    By Tempy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-29-2005, 01:05 PM
  7. Find method - finding multiple values
    By nathan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-23-2005, 06:05 PM

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