i have userform includes text boxes multiple formats. have initialize blank ("") , format them using afterupdate(). works fine, issues come possibility of user miss keying data first go around or clicking aimlessly on there screen. after input value formats correctly when move text box. if reselect text box move away again, clears value. , if text box formatted percent bugs out mismatch error.
here slice of current code:
private sub userform_initialize() valueanalysistextbox.value = "" capratetextbox.value = "" end sub private sub valueanalysistextbox_afterupdate() valueanalysistextbox.value = format(val(valueanalysistextbox.value), "$#,###") end sub private sub capratetextbox_afterupdate() capratetextbox.value = format(val(capratetextbox.value) / 100, "percent") end sub
any thoughts on how clean great.
is trying?
private sub valueanalysistextbox_afterupdate() dim amt double amt = val(replace(valueanalysistextbox.value, "$", "")) valueanalysistextbox.value = format(amt, "$#,###") end sub private sub capratetextbox_afterupdate() dim perct double perct = val(replace(capratetextbox.value, "%", "")) / 100 capratetextbox.value = format(perct, "percent") end sub
note: not doing other error handling. example, user typing "blah blah" or pasting else in textbox. sure can handle that.
Comments
Post a Comment