+ Reply to Thread
Results 1 to 16 of 16

Find partial date string within date column

  1. #1
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Angry Find partial date string within date column

    I have been unable to use the Find Method in order to find a substring of dates within a date column
    For example, I would like to find the string "08/1980" in a column which contains dates displayed in DD/MM/YYYY format in order to loop through all rows with a date in August 1980

    It works manually, and if I record a macro doing that search, executing the macro produces an error. The macro contains only one line :
    Selection.Find(What:="08/1980", ...).Activate
    And since the Find method does not work, there is no range returned and the Activate method runs into an error.

    Please note that the thing works for finding whole dates, using Find(What:=Cdate("1/8/80")...) This works OK. The problem is when searching for substrings

    Any help would be greatly appreciated !

    Jean-Marie

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Find partial date string within date column

    Jean-Marie -

    Use date filters on your column - and you don't need to activate or select a range to use it in VBA code:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you Bernie, this is a nice solution indeed, for most cases.
    Except for me for two reasons :
    1) my code is in a UserForm which is displayed on top of the sheet, which enables me to edit the content of a row and to search for particular values in any column. I would prefer a solution where I would not have to filter the underlying sheet.
    2) The sheet contains references to about 5000 speeches that were given over a period of about 40 years, and I receive comments on these speeches, which I must process. One comment will address the speech of such and such date, and sometimes there is an error on the date mentioned, the day or month or year can be wrong, and I must find the right speech concerned, looking at the speech title and summary compared to the comment.
    So for the problem to be expressed completely, I might be looking for the string "01/08" looking for all speeches given on a 1st of August, then spotting the right speech when looking at the title and summary !

    The manual search for such substrings works, but apparently not by macro !

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Find partial date string within date column

    If you are using a userform, then filtering the sheet will have no adverse effect on the userform. Finding and editing information from the found row is as easy as adding

    Please Login or Register  to view this content.

  5. #5
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Find partial date string within date column

    Your code only fails if the FIND fails, that is, the selected range contains no instances of the search string. You could use a variable to test if date was found.
    Please Login or Register  to view this content.
    BTW, you can also specify the search range instead of relying on selection:
    Please Login or Register  to view this content.
    Please click the Add Reputation star below any helpful posts, and use Thread Tools (up top) to mark your thread as SOLVED once you have your answer. Thanks!-Lee
    Last edited by leelnich; 08-22-2017 at 01:38 PM.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Find partial date string within date column

    Hello JMA119,

    Maybe it would be best if you could attach a sample workbook.

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  7. #7
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you for all your answers
    There is not much need to provide a worksheet to demonstrate the problem. It is very easy to reproduce :
    Type in a few dates on a given column of a worksheet,
    Then select that column, start recording a macro, search for a sub-string appearing in one of the dates : you will see that Excel finds it.
    Turn off macro recording
    Now select again the column and run the macro : it runs into an error.
    As leelnich mentioned, the problem stems from not finding a cell that matches the search. But why does it not find it by macro when if does find it by manual search ?

  8. #8
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you leelnich, but why the Find fails even if there is an instance of the searched string. That is the problem !

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Find partial date string within date column

    Thank you for your reply JMA119,

    My request for a sample Workbook is based on your statement in Post #3;

    1) my code is in a UserForm which is displayed on top of the sheet, which enables me to edit the content of a row and to search for particular values in any column. I would prefer a solution where I would not have to filter the underlying sheet.
    The attached sample Workbook works without a problem, and I cannot guess how you have your Userform and/or Code set up.

    Regards.
    Attached Files Attached Files
    Last edited by Winon; 08-23-2017 at 09:56 AM.

  10. #10
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Find partial date string within date column

    Are you ABSOLUTELY certain you're searching the right range? You could verify by adding this line just prior to search:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you a lot for your answers
    Leelnich : yes the search applies to the right range
    Winon : thank you for providing the excel file.
    I do not want to have to add columns with "day/month" and "month/year" combinations. However, your file was VERY USEFUL because it enabled me to find a partial explanation to the problem.

    It has to do with whether Excel detects the column to be a date column or not.
    In order to know if it does, filter the column and if Excel proposes chronological filters, it means it detects it as a date column. If it only proposes textual filters, then the column is not regarded by Excel as a date column.
    Now what I am trying to achieve with my Range.Find works fine if the column is not detected as a date column. I found this out because in Winon's file, the first column with what looks like DD/MM/YYYY dates is considered text by Excel.
    Now if anyone knows how to force Excel to consider a column as a textual columns, THAT WOULD SOLVE MY PROBLEM.
    Thank you !

  12. #12
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    PS Concerning filtering the column, for example with a criteria like "ends with 08/1980" : this does not work if the column is considered a date column. It works if the column is considered a textual column

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Find partial date string within date column

    Hello JMA119,

    In Post# 3, you state;

    I would prefer a solution where I would not have to filter the underlying sheet.
    Sorry, I missed that requirement. I have now prepared a sample Workbook which highlights your search, allowing you two options; Search by full Date, or by Months of a chosen year.

    Please try the attachment, I hope it suits you better, given the Date "constraints".

    Regards.
    Attached Files Attached Files
    Last edited by Winon; 08-26-2017 at 05:56 PM.

  14. #14
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you Winon, I really appreciate your efforts, and your Excel file is very well designed !
    But . . . in fact the column of dates in which the search is made is viewed by Excel as text cells, and therefore indeed the search for a partial string, or filtering on a partial string works.
    I have transformed the file so that the dates are seen as dates, and the search does not work any more
    So the problem is not really solved yet !
    But thank you for your efforts !

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Find partial date string within date column

    Thank you kindly for your response,

    I would still like to see a sample of your Workbook and code attempt.

    Without any other ideas, or better clarity with a sample from you, I hereby offer you my last try where the date selected is returned in a Cell below the one stating Date. That is in Fact a date and not Text.

    Hope that helps!

    Kind regards.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    08-22-2012
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Find partial date string within date column

    Thank you again Winon
    Please find enclosed a simple excel file
    In the Blue Search In box, select either of two date columns
    In the blue Search What box, type in something like "15-oct"
    You will see that the search works in the Payment date column and not in the Order date column
    The Payment date column is seen as a text column whereas the Order date column is seen as a date column
    Hope you understand what I was trying to achieve
    Jean-Marie
    Attached Files Attached Files

+ 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. Replies: 4
    Last Post: 03-30-2015, 03:20 PM
  2. Find next date in a column and count how many rows fall in the first date
    By zookeepertx in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-11-2014, 10:50 AM
  3. [SOLVED] find date string and paste into different column, same row
    By rdowney79 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-06-2014, 11:27 AM
  4. [SOLVED] vba code to find Duplicate Values and Newest date(Max) date in the Corresponding Column(ce
    By Pradu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 05:20 AM
  5. [SOLVED] Vlookup, Match (Search or Find) partial string within string in a Cell
    By dluhut in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-28-2013, 12:40 PM
  6. [SOLVED] Find string in Column A then verify Date in Column B
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-17-2012, 07:13 PM
  7. [SOLVED] Adding if partial date string is matched
    By Steven811 in forum Excel General
    Replies: 11
    Last Post: 06-25-2012, 10:11 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