how value between 2 asterisk in excel?
for example:
i have these: txi*gs*346.32*13*sp*on*3***103634408rt0001
i want value 346.32
i these data a1:a20 how can replace them using vba?
sub extractfirstnumber() set objregex = createobject("vbscript.regexp") ' match numbers of form 123 or 123.45 objregex.pattern = "\d+(\.\d*)?" ' iterate on first 20 rows in first column = 1 20 set objmatch = objregex.execute(cells(i, 1).value) if objmatch.count = 1 ' if there match, replace cell value cells(i, 1).value = objmatch(0) end if next end sub
edit
sub extractfirstandthirdnumber() set objregex = createobject("vbscript.regexp") ' match numbers of form 123 or 123.45 between asteriks objregex.pattern = "\*(\d+(\.\d*)?)" objregex.global = true ' iterate on first 20 rows in first column = 1 20 set objmatch = objregex.execute(cells(i, 1).value) if objmatch.count >= 2 ' if there match, replace cell value 'cells(i, 1).value = objmatch(0) cells(i, 3).value = objmatch(0).submatches(0) cells(i, 4).value = objmatch(2).submatches(0) end if next end sub
Comments
Post a Comment