vba help - extract data from text value via Regular expresion

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

I want to extract no of records and Amount value from text file via regular expression.


Sub-Total Product X3 Rejected : No of Records = 0000 Amount = 0.00+
Generated : No of Records = 0008 Amount = 65,000-
Received : No of Records = 0009 Amount = 75,000-



Sub-Total Product X4 Rejected : No of Records = 0012 Amount = 0.00+
Generated : No of Records = 0016 Amount = 15,000-
Received : No of Records = 0019 Amount = 25,000-




expected output after Reading Text value
RecordsAmount
Rejected00
Generated 8-65000
Received9-75000
Rejected120
Generated 1615000
Received1914000



thanks
mg
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Book1
FGHI
2Sub-Total Product X3 Rejected : No of Records = 0000 Amount = 0.00+
3Generated : No of Records = 0008 Amount = 65,000-
4Received : No of Records = 0009 Amount = 75,000-
5
6
7
8Sub-Total Product X4 Rejected : No of Records = 0012 Amount = 0.00+
9Generated : No of Records = 0016 Amount = 15,000-
10Received : No of Records = 0019 Amount = 25,000-
11
12
13RecordsAmount
14Rejected00000.00
15Generated 008-65,000
16Received0009-75,000
17Rejected00120.00
18Generated 016-15,000
19Received0019-25,000
20
21
Sheet1
Cell Formulas
RangeFormula
G14:G16G14=TRIM(LEFT(SUBSTITUTE(MID(F2,FIND(F14,F2)+LEN(CONCATENATE(F14," : No of Records = ")),99)," ",REPT(" ",99)),9))
H14H14=TRIM(LEFT(SUBSTITUTE(MID(F2,FIND(" Amount = ",F2)+LEN(" Amount = "),99),"+",REPT(" ",99)),99))
H15:H16H15=IF(ISNUMBER(SEARCH("-",TRIM(LEFT(SUBSTITUTE(MID(F3,FIND(" Amount = ",F3)+LEN(" Amount = "),99),"+",REPT(" ",99)),99)))),"-"&TRIM(LEFT(SUBSTITUTE(MID(F3,FIND(" Amount = ",F3)+LEN(" Amount = "),99),"-",REPT(" ",99)),99)),TRIM(LEFT(SUBSTITUTE(MID(F3,FIND(" Amount = ",F3)+LEN(" Amount = "),99),"+",REPT(" ",99)),99)))
G17:G19G17=TRIM(LEFT(SUBSTITUTE(MID(F8,FIND(F17,F8)+LEN(CONCATENATE(F17," : No of Records = ")),99)," ",REPT(" ",99)),9))
H17:H19H17=IF(ISNUMBER(SEARCH("-",TRIM(LEFT(SUBSTITUTE(MID(F8,FIND(" Amount = ",F8)+LEN(" Amount = "),99),"+",REPT(" ",99)),99)))),"-"&TRIM(LEFT(SUBSTITUTE(MID(F8,FIND(" Amount = ",F8)+LEN(" Amount = "),99),"-",REPT(" ",99)),99)),TRIM(LEFT(SUBSTITUTE(MID(F8,FIND(" Amount = ",F8)+LEN(" Amount = "),99),"+",REPT(" ",99)),99)))
 
Upvote 0
For your regular expression, try the following matching pattern...

VBA Code:
=\s?(\d{4}).*=\s?((?:\d{1,3},)*(?:\d{1,3})(?:\.00)?[-+])

For an example and explanation, see the following link...


Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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