PDA

View Full Version : if find string copy that cell to right column



parscon
02-27-2014, 02:31 PM
I have a data like this in column K: i need to check all row of column K

K10 :SER NO 2221 -, EXS 44252116,2131M
K11 : SV129 (EXS 2233223), SRM2145
K12 : DATA(2233223), SRM2145
K13 : (2233223,123242), SRM2145

I need a VBA find the string that EXS and one space and number and copy to right column of that column
also copy (onlyNumber) like K12
also copy (onlynumber,onlynumber) like K13

and The result will be :

L10: EXS 44252116
L11: EXS 2233223
K12: (2233223)
K13: (2233223,123242)

Please help me on this subject.

THankyou

lecxe
02-28-2014, 03:12 AM
Hi

Try in L10:

=ExtractData(K10)

Copy down




Function ExtractData(s As String) As String

On Error Resume Next
With CreateObject("VBScript.RegExp")
.Pattern = "EXS \d+|\(\d+(,\d+)*\)"
ExtractData = .Execute(s)(0)
End With
End Function

ashleyuk1984
02-28-2014, 03:32 AM
Awesome!! I should really start learning regular expressions for stuff like this. Could come in handy!

Good job lecxe

lecxe
02-28-2014, 05:02 PM
I should really start learning regular expressions for stuff like this. Could come in handy!

I agree, handy ... and a lot of fun to work with! :content: