Macro for extracting data

sparkerk1

New Member
Joined
Nov 1, 2017
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
hi

i have below sample data , from which i want to extract only certain value only

5 TK 468 M 06JUL 1 ODSIST HK4 2140 2305 06JUL E TK/VGRWLL

Output required

TK 468 06JUL ODSIST 2140 2305 06JUL TK/VGRWLL
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
hi


based on the code below just a small adjustment required , it should remove the highlighted part also

J5CG4Z
BOMVS316E/2005NM/5JUL20
1.SINGH/RANGPAL MR
2 QR 146 H 10JUL 5 BCNDOH HK1 1440 2145 10JUL E QR/J5CG4Z
3 VR 053 Y 11JUL 6 DOHDEL GK1 0800 1405 11JUL SUKANYA


Sub test()
Dim a, i As Long, m As Object, dep, des, txt As String
With Range("a1", Range("a" & Rows.Count).End(xlUp))
a = .Value
With CreateObject("VBScript.RegExp")
.Global = True
For i = 2 To UBound(a, 1)
txt = a(i, 1)
.Pattern = "[^\u0021-\u007F]+"
txt = Application.Trim(.Replace(txt, " "))
.Pattern = "^ *\d+ *(\d[A-Z]|[A-Z][A-Z\d]) *(\d+) *[A-Z] *(\d{1,2}[A-Z]{3}) *\d[\* ]([A-Z]{3})" & _
"([A-Z]{3}) *([A-Z]{2}\d+) *(\d{4} *\d{4} *\d{1,2}[A-Z]{3}) *[A-Z] *(.*)$"
If .test(txt) Then
Set m = .Execute(txt)(0).submatches
dep = Application.VLookup(m(3), Sheets("airport").Range("a:b"), 2, False)
des = Application.VLookup(m(4), Sheets("airport").Range("a:b"), 2, False)
If IsError(dep) Then dep = m(3)
If IsError(des) Then des = m(4)
a(i, 1) = Application.Trim(.Replace(txt, "$1 $2 $3 " & dep & " " & des & " $6 $7 $8 "))
End If
Next
End With
.Value = a
End With
End Sub
 
Upvote 0
Looks like you posted the same question in another forum without informing us :rolleyes: ... The above code is not my code nor can I edit it
 
Upvote 0
Cross posted Macro required to skip rows if there is a . Between in the data [SOLVED]
and macro to delete unwanted characters and give output on the same cel

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,310
Members
449,499
Latest member
HockeyBoi

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