+ Reply to Thread
Results 1 to 7 of 7

Finding a Date with the Find Command

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Finding a Date with the Find Command

    Here is the offending line:
    Please Login or Register  to view this content.
    The value I am looking for is 6/14/2017, the value in the cell is 6/14/2017 - yes both are dates and not strings. Home row is the row that contains the dates. It also contains other garbage like strings for header "W/E x/y" - could this garbage interfere with the search. All the web searches I've done says I'm doing it right. I have US settings on my computer and both this spreadsheet and the workbooks that it reads are on the same settings.

    A version of this program that looks for the strings matching the W/E dates works perfectly. I'm trying to adapt it to find a date rather than a string.

    The zip file contains the program and two sample files: on the program file, In Cell B1 on the control panel enter the path name of the directory where the data files are. Put the data files in this directory. The output should provide two lines of data on the backlog sheet: one for Sample Data Sheet A and another for Sample Data Sheet B.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Finding a Date with the Find Command

    Have you tried using Application.Match and Value2?

    That worked for me and returned the column, 20, the date was in.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Finding a Date with the Find Command

    I have not but I will try it. I was hoping to use a "native" VBA call than a worksheet function, but it's a quick run, so it probably doesn't matter. Too close to quitting time to try it now . I'll call back in the morning.

    You did drop something new on me: what does .resize do?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Finding a Date with the Find Command

    Well that should be Resize, I was working in the Immediate Window so it didn't get changed to proper case.

    Anyways, it well, resizes a range - in this case it resizes the range to search in by 52 columns.

    By the way, there's a typo in the code I posted - it should be shs.Cells(homeRow, 1) not shs.Cells(homeRow).

    I did kind of get away with that though because Cells(1) is equivalent to Cells(1,1), ie it's the very first cell in the sheet, A1.

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Finding a Date with the Find Command

    I've made the adjustment and it does seem to work. Thanks for the correction on the typo. HomeRow doesn't always work out to 1. The people who track this data play loose with the format of the report. Our Phoenix office uses row 1 to record the daily temperature. Some offices start in column A others in column D.

    I have another question: how do I test for the condition when the formula does not find a match - I want the program to "die gracefully."

    Finally. I have used the Find command to find dates in other programs successfully using the exact syntax of the regular post. I will have to go back and figure out what might be different about those programs. One of the things I can think of is that there are strings that are also interspersed in the range in which I am looking. I'll set up a test for that theory and if it proves to be the problem, I may be back in the forum looking for a work-around.

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Finding a Date with the Find Command

    It is not an issue of having strings in the search. Find doesn't work with dates - at least as I can find in my search. So I wrote my own function to emulate it.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Finding a Date with the Find Command

    Find does work with dates but it can be very temperamental, that's basically why I suggested using Application.Match and that's what I tend to use too, especially when the ultimate aim is to find a column/row.

    As for handling the value not being found with Application.Match, try something like this.
    Please Login or Register  to view this content.
    Obviously that's an example and uses message boxes for illustration purposes.

    The main thing is that you declare the variable that takes the result from Application.Match as Variant which to allow it to accept error values.

    When Application.Match (or any other worksheet function) fails it returns an error value, so we can check for that using IsError.

+ 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] Request help finding text next to a date, finding the same date in another column...
    By Biff Malibu 636 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-11-2016, 12:34 AM
  2. [SOLVED] Finding a command button in a row and deleting it.
    By Ataraxicatom in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-19-2014, 12:17 PM
  3. [SOLVED] Find function not finding date in row
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2014, 11:22 AM
  4. VBA | Find Today's Date by Command Button
    By maintguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 01:04 PM
  5. InStr command finding too many matches
    By SarahPintal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2010, 03:10 AM
  6. vba: find command, finding exact values
    By icylemontea in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2010, 02:48 PM
  7. Not finding string error fix in macro find command
    By Aussie_Striker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2007, 05:40 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