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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Maybe a UDF ?

Code:
Function PON(s As String) As String
With CreateObject("VBScript.RegExp")
  .Pattern = "([0.9 0-9]+?[W|kW]+)"
  If .Test(s) Then PON = .Execute(s)(0).SubMatches(0)
End With
End Function


Excel 2007
AB
1aaksdhasdkjh 400W asjhasdjh400W
2blabla 400W blablabla blabla400W
3blabla,0.5kW blabla bla bla bla0.5kW
4blabla,25.5kW blabla bla bla bla25.5kW
Sheet1
Cell Formulas
RangeFormula
B1=PON(A1)
B2=PON(A2)
B3=PON(A3)
B4=PON(A4)
 
Upvote 0
Be a little more helpful if you had real data to look through. Someone elses excel ninjitsu may be able to do something with what you have my mine is not so much lol
 
Upvote 0
Thanks Michael for your reply!
Nice approach and it works.

I have another similar, but with VA and KVA. The issue here is sometimes, I got product name with 8V6B-500VA and the formula give me 8V. How can I force "VA" (Not only 'V")

Thanks a lot!
 
Upvote 0
you'll need to provide a couple more examples of the data AND what you want as a result....Excel doesn't really know which you want, so it provides the first sample.
If there is always a "-" between the numbers ....try using text to columns to split them first, with "-" as the delimiter !
 
Upvote 0
Sure, let me give you real data with the expected results

1510001464#&Bộ lưu điện dự phòng 500KVA 3P/4W 380V500KVA
1510001465#&Bộ lưu điện dự phòng 500kva 3P/4W 380V500kva
KDTC-3307#&Nguồn S8VS-06024 (chuyển đổi nguồn điện đầu vào AC 220V xoay chiều đầu ra 24V một chiều), hàng mới 100%#N/A
Bộ lưu điện ABC Offline 1000VA - Model CV1000 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)1000VA
Bộ lưu điện Lumix Online 500vaa - Model LU500 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)500va
Bộ lưu điện 8V6B-500VA - Model 8V6B500 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)500VA

<colgroup><col><col></colgroup><tbody>
</tbody>


PS: Sometimes it's in UPPER or lower case.

Thanks a lot!
 
Last edited:
Upvote 0
sorry, I'm confused....what does counting UPPER and LOWER case have to do with extracting the results.
I think you need to post a sample of data with what you want to do with it.
Adding to the requirements with each post makes it very difficult to provide useful information.
Have a think about everything you need, then post back !
 
Upvote 0
Sure, let me give you real data with the expected results

1510001464#&Bộ lưu điện dự phòng 500KVA 3P/4W 380V500KVA
1510001465#&Bộ lưu điện dự phòng 500kva 3P/4W 380V500kva
KDTC-3307#&Nguồn S8VS-06024 (chuyển đổi nguồn điện đầu vào AC 220V xoay chiều đầu ra 24V một chiều), hàng mới 100%#N/A
Bộ lưu điện ABC Offline 1000VA - Model CV1000 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)1000VA
Bộ lưu điện Lumix Online 500vaa - Model LU500 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)500va
Bộ lưu điện 8V6B-500VA - Model 8V6B500 (Kèm sách hướng dẫn sử dụng), (Hàng mới 100%)500VA

<tbody>
</tbody>


PS: Sometimes it's in UPPER or lower case.

Thanks a lot!

In the 5th line 500vaa is a typo?
 
Upvote 0
Hi Michael,
I've edited my message while you were writting yours. Hope my revised message makes more sense.

Thank you
 
Upvote 0
Hi István,
It is a typo from the source. (Not from me). So we still need to show only 500va xD
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,660
Members
449,114
Latest member
aides

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