excel - Get sub-parts of text in cell -
i have spreadsheet in excel 1 product per row , height , width of each item according text in column. have dimensions text in column:
8" h x 8" w 2.5" h x 3.5" w per side 8" h x 8" w 1 color left side 1" h x 3" w
and put height in column (b) , width in column (c). this:
(a) (b) (c) 8" h x 8" w 8 8 2.5" h x 3.5" w 2.5 3.5 per side 8" h x 8" w 8 8 1 color left side 1" h x 3" w 1 3
i started snippet can't figure out how desired part:
sub numberextractor() dim cell integer cell = 2 449 if instr(cells(cell, 17), """ h") > 0 cells(cell, 18).value = left(cells(cell, 17), instr(cells(cell, 17), " ") - 1) end if if instr(cells(cell, 17), """ w") > 0 cells(cell, 19).value = right(cells(cell, 17), instr(cells(cell, 17), " ") + 2) end if next cell end sub
logic:
- use unique delimiter. using
sidz
. - replace
" w
""
- replace
" h x
sidz
- first split on
space
, on unique delimiter
try this.
option explicit sub sample() dim rng range, acell range dim ar dim ht double, wt double dim stemp string, sdelim string dim long sdelim = "sidz" set rng = range("a1:a4") each acell in rng stemp = acell.value stemp = replace(replace(stemp, """ w ", ""), """ h x ", sdelim) ar = split(stemp) = lbound(ar) ubound(ar) if ar(i) "*" & sdelim & "*" acell.offset(, 1).value = split(ar(i), sdelim)(0) acell.offset(, 2).value = split(ar(i), sdelim)(1) end if next next acell end sub
Comments
Post a Comment