Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2016, 03:26 AM
Authorized User
 
Join Date: Apr 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Default Excel VBA RegEx not working

Hi folks,
I have a simple UDF in Excel that is meant for extracting date from a given cell. The RegEx pattern works fine in online Regex101 tester but when used in Excel, I get "#Value " error. I have tried to figure it out, so far without any luck.

My date in Excel is put this way: Date: 02-DEC-15

Here is the function I am using:

Code:
Function getOrderDate(oDate As String)

Dim allDates As Object
Dim REDate As Object
Dim resultingDate
Set REDate = CreateObject("vbscript.regexp")


REDate.Pattern = "\d{2}\-\D{3}\-\d{2}"   '"\d{2}\-\D{3}\-\d{2}"
REDate.Global = True
REDate.ignorecase = True

Set allDates = REDate.Execute(oDate)

If (allDates.Count <> 0) Then
resultingDate = allDates.Item(0).submatches.Item(0)

getOrderDate = resultingDate

End If

End Function
Your help would be much appreciated.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel formula not working in vba yogeshyl Excel VBA 2 December 12th, 2007 02:27 AM
Working JavaScript Regex vinaura Javascript How-To 0 August 16th, 2007 01:06 PM
Excel formula not working in VBA yogeshyl Excel VBA 2 July 19th, 2007 03:57 AM
Excel vba query not working, pls help me. kavisundar SQL Language 0 May 16th, 2007 10:14 AM
REGEX Problem - Excel Hangs sreins VB How-To 0 December 5th, 2006 05:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.