Dears,
I ask for help, that I have some data in one column like that
35515Mai Mohamed Shebl83... 7:00 AM 4:00 PM
and I have the code which extract the time "7:00 AM 4:00 PM"
and I have some row that contain the words "D" and "Annual" at the last of row words that I need to extract it also, I ask to edit the below code to get it
38357Noura Ezzat Ibrahim838...Do
39042Samar Alam Abd El Azi...Annual
I ask for help, that I have some data in one column like that
35515Mai Mohamed Shebl83... 7:00 AM 4:00 PM
and I have the code which extract the time "7:00 AM 4:00 PM"
and I have some row that contain the words "D" and "Annual" at the last of row words that I need to extract it also, I ask to edit the below code to get it
38357Noura Ezzat Ibrahim838...Do
39042Samar Alam Abd El Azi...Annual
Code:
Option Explicit
Sub ExtrTime()
Dim RE As Object, MC As Object, M As Object
Dim vSrc As Variant, vRes() As Variant
Dim rRes As Range
Dim I As Long
Dim S As String
'Get Source Data
vSrc = Range("a1", Cells(Rows.Count, "A").End(xlUp))
'Set Results Range and array
Set rRes = Range("B1").Resize(UBound(vSrc))
ReDim vRes(1 To UBound(vSrc), 1 To 1)
'Regular Expression Engine
Set RE = CreateObject("vbscript.regexp")
With RE
.Global = True
.ignorecase = False
.Pattern = "\b((?:1[0-2]|\d):[0-5]\d\s+[AP]M)"
End With
'Extract times
For I = 1 To UBound(vSrc)
S = vSrc(I, 1)
If RE.test(S) Then
Set MC = RE.Execute(S)
For Each M In MC
vRes(I, 1) = vRes(I, 1) & Space(1) & M
Next M
vSrc(I, 1) = Trim(vSrc(I, 1))
End If
Next I
rRes = vRes
End Sub