Link to home
Start Free TrialLog in
Avatar of hallpett
hallpett

asked on

Calculated field in userform

I have a userform with two textboxes. Textbox1 have controlsource C2, Textbox2 have controlsource C3. How can I show the sum of this two fields on the userform. I tried with another Textbox with controlsource cell C4 where I put =C2+C3. But the value from the userform overwrites the formula in C4 so this does'nt work. Appreciate an tips.
Avatar of krishnakrkc
krishnakrkc
Flag of India image

Hi,

what about

TextBox3.Value = TextBox1.Value + TextBox2.Value

Avatar of hallpett
hallpett

ASKER

I'm not so experienced with vba in excel. Where should I put this line to make it work?
Avatar of GrahamSkan
Perhaps You should set the Locked property of TextBox3 to True, so that it can't be edited
"Perhaps You should set the Locked property of TextBox3 to True, so that it can't be edited"
Can't find a Locked property but I have tried to set the Enabled property to false. Don't work. The value you see when you open the user form will still overwrite the formula in the controlsource cell.
How does that value get there? In my tests, the value is taken from the cell when the form is initialised.
The value is taken from the cell when the form is opened, but when you change value in textbox1 (cell C2) or textbox2 (cell C3), then textbox3 (cell C4, with formula =C2+C3) get a new value from cell C4 that textbox3 overwrites back to C4. I'm propably not the best to explain but hope this is understandable.
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked just fine. Thank you!