VBA: Parse preceding numbers from string -
i need parse 2 substrings string starts numeric text followed alpha-numeric text. strings can vary bit, not much. below examples of incoming format , strings need:
"00 10 50 information bidders" ==> "00 10 50", "information bidders" "001050 information bidders" ==> "001050", "information bidders" "00 10 50 - information bidders" ==> "00 10 50", "information bidders" "001050 -- information bidders" ==> "001050", "information bidders"
i hoping half dozen lines of vba, code turning loop i'm testing every character in string see changeover numeric-only non-numeric, parsing string based on changeover location. not big deal, messier hoping for. there vba functions eliminate need iterate through each string character?
well, question poor, don't state if want done in word, excel etc...
i've assumed excel. so, either want, or give start! reads value in column , spits results out column b.
sub formatmeplease() dim row integer row = 1 while (true) if range("a" & row).value = "" exit end if dim originalvalue string originalvalue = range("a" & row).value originalvalue = replace(originalvalue, chr(34), "") 'chr(34) double quote originalvalue = replace(originalvalue, "-", "") 'be gone oh evil dash originalvalue = replace(originalvalue, " ", " ") 'double white space? never! single white space more enough dim result string result = chr(34) = 1 len(originalvalue) dim currentcharacter string currentcharacter = mid(originalvalue, i, 1) if (isnumeric(currentcharacter) or currentcharacter = " ") result = result + currentcharacter else result = left(result, - 1) result = result & chr(34) & ", " & chr(34) result = result & mid(originalvalue, i) exit end if next result = result & chr(34) range("b" & row).value = result row = row + 1 loop end sub
screen shot using excel:
Comments
Post a Comment