pattern matchimg in VBA Excel using LIKE operator

J

johnkrehlik

I have cells containing a series of dates in the format: 8/21/2006 or
11/6/2005 or 11/23/2005 or 8/7/2006. I want to identify these cells by
the pattern in a VBA module.

I have tried these listed below and variations without success:
Function IsDate(xDate As String) As Boolean
If xDate Like "*/*/*" Then
IsDate = True
Else
IsDate = False
End If
End Function

Function IsDate(xDate As String) As Boolean
If xDate Like "*/*/####" Then
IsDate = True
Else
IsDate = False
End If
End Function

Function IsDate(xDate As String) As Boolean
If xDate Like "*[/]*[/]*" Then
IsDate = True
Else
IsDate = False
End If
End Function

I have also declared Option Compare Text and not declared Option
Compare Text.

Any ideas?
 
T

Tom Ogilvy

Maybe:

Function MyIsDate(xDate as String) as Boolean

MyIsDate = xDate like "##/##/####" or xDate like "#/##/####" _
or xDate like "##/#/####"
End Function


What about the built in IsDate function?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top