vba - Replace function converts text format to number format. Is it excel bug? -
i'm not newbie in excel or googling, behavior surprising/illogical:
- format column "a" text
- write numbers cells, e.g. 74 a1, a2 , a3 - formatted text, not sum up, looks fine expected
- go find - replace 74 75
- after replace 75's sum up, behaving numbers, when cells still formatted text! can't why?!
this "bug" (?) causing me troubles in vba, because following code not convert data expected results ('numbers' in text format) , can't text format:
selection.replace what:="74", replacement:="75"
same result when try of these methods:
selection.replace what:="74", replacement:=format("75", "@") selection.replace what:="74", replacement:=cstr("75") selection.replace what:="74", replacement:="75" selection.numberformat = "@"
only solution works this:
selection.replace what:="74", replacement:="'75"
but don't want apostroph in cell ...
is there other way how replace text, number in cell - text, number? feel dummy spend hour thinking such basics!
edit: method usage of named range gives me 75's numbers (cell format text):
selection.replace what:="74", replacement:=range("number_75_in_text_format").text
you need describe how getting this. try running either of these:
sub bugdemo() activecell .clear .numberformat = "@" .value = "101" .replace what:="0", replacement:="7" end end sub sub bugdemo2() activecell .clear .numberformat = "@" .value = "101" .replace what:="101", replacement:="7" end end sub
after replacement, values remain text
Comments
Post a Comment