Extract 1 string between space (or ,) and W (or kW)

dudumomo

Board Regular
Joined
Jun 3, 2014
Messages
65
Hi there,

I have some lines like these:
blablabla blabla bla 400W blabla ==> 400W
blabla 400W blablabla blabla ==> 400W
blabla,0.5kW blabla bla bla bla ==> 0.5kW

I'm trying to build a formula to extract those data accordingly, but seems they can be betwen a coma or a space and a kW or W, I have difficulties to extract the data.
And also, we have to make sure before the kW or W, is a number. As some brand name or description could be let's say "Cowboy", we should not take this one but only when there is a number.

Any idea on how to do it?
The best will also be if kW, it converts in W (/1000) to get clean data.

Thanks for your help!
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
...right... well I will still need some manual checks then.
Thanks for clarifying it.
OK, so here's my next attempt. You may need to do some manual checking as discussed.

Code:
Function ExtractVA(s As String) As String
  Dim x As Object
  Dim i As Long
  
  With CreateObject("VBScript.RegExp")
    .IgnoreCase = True
    .Global = True
    .Pattern = "(\d+,?)+\.?\d* *k?va"
    Set x = .Execute(s)
    For i = 1 To x.Count
      ExtractVA = ExtractVA & ", " & x(i - 1)
    Next i
    ExtractVA = Mid(ExtractVA, 3)
  End With
End Function


Excel Workbook
AB
21510001464#&B? luu di?n d? phng 500KVA 3P/4W 380V500KVA
31510001465#&B? luu di?n d? phng 500kva 3P/4W 380V500kva
4KDTC-3307#&Ngu?n S8VS-06024 (chuy?n d?i ngu?n di?n d?u vo AC 220V xoay chi?u d?u ra 24V m?t chi?u), hng m?i 100%
5B? luu di?n ABC Offline 1000VA - Model CV1000 (Km sch hu?ng d?n s? d?ng), (Hng m?i 100%)1000VA
6B? luu di?n ABC Offline 1,254.63VA - Model CV1000 (Km sch hu?ng d?n s? d?ng), (Hng m?i 100%)1,254.63VA
7B? luu di?n Lumix Online 500vaa - Model LU500 (Km sch hu?ng d?n s? d?ng), (Hng m?i 100%)500va
8
9B? luu di?n 8V6B-500VA - Model 8V6B500 (Km sch hu?ng d?n s? d?ng), (Hng m?i 100%)500VA
10bla bla 33.24 VA etc33.24 VA
11bla bla 0.24 kVA etc0.24 kVA
121510001464#&B? luu di?n model va phng 500KVA 3P/4W 380VA500KVA, 380VA
131510001464#&B? luu di?n model va phng
14model: A-500M-5 . AC: 200-240VAC and the formula give me 250KVA.240VA, 250KVA
15
VA KVA
 
Upvote 0
Nice!

And if we ignore the 500vaa and to stick to 500va? Because I have a lot with VAC and very few with error like vaa. WIll be easier for me to clean.

Thanks a lot!
 
Upvote 0
Nice!

And if we ignore the 500vaa and to stick to 500va? Because I have a lot with VAC and very few with error like vaa. WIll be easier for me to clean.

Thanks a lot!
To ignore items like "vaa" or "VAC" then try just changing this line
Rich (BB code):
.Pattern = "(\d+,?)+\.?\d* *k?va(?= |$)"
 
Upvote 0
@ Peter

As far as I can see with the new Pattern the code does not recognize the search string followed by punctuation mark, for example "500 KVA,".
 
Upvote 0
@ Peter

As far as I can see with the new Pattern the code does not recognize the search string followed by punctuation mark, for example "500 KVA,".
Thanks for pointing that out István.

That was (mistakenly) deliberate as I thought all the OP's valid data had a space after the "VA". On receiving your message and re-checking the thread, I now remember post #25. :oops:

I would see if this changed pattern line suited the OPs requirements
Rich (BB code):
.Pattern = "(\d+,?)+\.?\d* *k?va(?![a-z])"
 
Upvote 0

Forum statistics

Threads
1,214,407
Messages
6,119,332
Members
448,888
Latest member
Arle8907

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