macro to search a cell for date format

Maui

Board Regular
Joined
Jan 13, 2006
Messages
159
does anyone know of a way I can search a cell from roght to left until I find a date format and the paste that format in a cell.

anyone got any ideas to get me started.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
What is this date format you're looking for? Are you wanting to past a date value or format a different cell or what? Please provide some more details about what you are trying to do exactly.
 

Maui

Board Regular
Joined
Jan 13, 2006
Messages
159
I have cells like this

040706-040806 32755MR 2630MR
120506-270706 90397MR
010706-310706 23414UNITS 26668UNITS
040706-010806 182605MR 39MR
040706-010806 1564MR 1259MR 285850MR
050706-020806 667952MR

But not always in this easy format, sometimes the dates are at end of the cell sometimes at begining. So I cant do an easy mid(a1,6)"/"mid(etcetc

I want to be able to pick up the second date 040806 and paste that in a cell then search the next cell down.
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
hi
try
Code:
Sub test()
Dim r As Range, mItem As Object, i As Integer
With CreateObject("VBScript.RegExp")
   For Each r In Range("a1",Range("a" & Rows.Count).End(xlUp))
      .Pattern = "(0?[1-9]|[1-2][0-9]|3[0-1])(0?[1-9]|1[1-2])0[0-9]"
      .Global = True
      If .test(r.Value) Then
         Set mItem = .execute(r.Value)
         For i = 0 To mItem.Count -1
            r.Offset(, i +1).Value = mItem.item(i)
         Next
      End If
   Next
End With
End Sub
 

Forum statistics

Threads
1,136,261
Messages
5,674,704
Members
419,520
Latest member
Jennifer4Dillon

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
Top