Search for string with forward slashes in numeric date format

Larissalle

New Member
Joined
May 12, 2015
Messages
5
I'm trying to do a search in a string that has a numeric date "m/d/yyyy." I just want to know if the string contains a date in this or similar numeric format such as "mm/dd/yyyy." I don't need to retrieve the date itself. I am able to use the following simple search to find occurrences of one slash. I am hoping that there is a way to search on /#/ where # is a numeric wildcard, but even a nonnumeric wildcard will probably pick up most of the instances I'm looking for. Or, is there a way to search for the date formats above? If so, I haven't been able to find them.

What I currently have: =IF(ISERROR(FIND("/",G28)),0,1)

What I would like: =IF(ISERROR(FIND("*/#/*",G28)),0,1) or "m/d/yyyy" or "mm/dd/yyyy"

Can someone help?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This UDF should do what you want after you install it. It will search the string in a cell and return "Date_Text Format" if the string contains a date having the format m/d/yyyy or mm/dd/yyyy and is a legitimate date. The UDF can be used like any worksheet function (see example below- notice that O21 does not contain a legitimate date).
Excel Workbook
OP
195/25/2015Date_Text Format
20abc/def/2015No Date_Text Format
2105/32/1999No Date_Text Format
22Joe CV 1/31/2015 CASTDate_Text Format
23Joe CV 01/3/2015 CASTDate_Text Format
Sheet3


To install the code:
1. With your workbook active press Alt and F11 keys. This will open the VBE window.
2. In the project tree on the left of the VBE window, find your project and click on it.
3. On the VBE menu: Insert>Module
4. Copy the code from your browser window and paste it into the white space in the VBE window.
5. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
6. Press Alt+F8 keys to run the code
7. Make sure you have enabled macros whenever you open the file or the code will not run.

Code:
Function IsDateFormat(S As String)
'Determines if a text entry is a date formatted as text in the format mm/dd/yyyyy or m/d/yyyy
With CreateObject("VBSCript.regexp")
    .Global = True
    .Pattern = "\b(0?([1-9]|10|11|12))\/(0?[1-9]|[1-2][0-9]|3[0-1])\/\d{4}\b"
    If .test(S) Then
        IsDateFormat = "Date_Text Format"
    Else
        IsDateFormat = "No Date_Text Format"
    End If
End With
End Function
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,635
Members
449,043
Latest member
farhansadik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top