VBA Extracting Date from String

tabletopjoe

New Member
Joined
Jan 10, 2018
Messages
6
Hello, I am creating a macro that regularizes file names and I'm having difficulty assigning the dates within filenames to a variable. The file names look something like this:

"Grants Report S-17, First Response, dated 3-14-2015"

Alternatively they might look like this:

"3-14-2015 1st Response from Mike to Grants Report S-17"

And so forth. The only piece I'm missing is how to dynamically extract dates from the filenames. Their format varies a bit, but I can work around those variations and I am just looking for ways to identify MMDDYYYY out of any particular string and assign that date to a variable. The resulting DateVariable is concatenated along with the rest of the filename's pieces like this:

Code:
ResultName = ReportNum & ResponseNum & " " & ResponseSource & " " & DateVariable

Any tips & tricks are most appreciated!
 
Hello, I am creating a macro that regularizes file names and I'm having difficulty assigning the dates within filenames to a variable. The file names look something like this:

"Grants Report S-17, First Response, dated 3-14-2015"

Alternatively they might look like this:

"3-14-2015 1st Response from Mike to Grants Report S-17"

And so forth. The only piece I'm missing is how to dynamically extract dates from the filenames. Their format varies a bit, but I can work around those variations and I am just looking for ways to identify MMDDYYYY out of any particular string and assign that date to a variable. The resulting DateVariable is concatenated along with the rest of the filename's pieces like this:

Code:
ResultName = ReportNum & ResponseNum & " " & ResponseSource & " " & DateVariable

Any tips & tricks are most appreciated!


(Update --> )

For anyone else stumbling around fecklessly looking for help with a similar question, here are some useful resources I've since found on Regular Expression and the like:

http://analystcave.com/excel-regex-tutorial/

http://refiddle.com/

https://docs.microsoft.com/en-us/do...s/regular-expression-language-quick-reference
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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