Text Boxes

Ben S

Board Regular
Joined
Oct 21, 2002
Messages
124
How would i automatically populate a textbox with the sum of 2 other textboxes.

E.g Text box 1 = £6000
Text box 2 = £3000

Text Box 3 would automatically populate with £9000.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Barry Katcher

Well-known Member
Joined
Feb 25, 2002
Messages
4,053
Andrew, doesn't work for me. Your formula, with = in front, gives #NAME?. Without the = give label in the cell. Where do you put formula, in text box 3 or in a cell in the spreadsheet?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
That was VBA code not a worksheet formula.

Code:
Private Sub TextBox1_LostFocus()
    TextBox3.Value = Val(TextBox1.Value) + Val(TextBox2.Value)
End Sub
Private Sub TextBox2_LostFocus()
    TextBox3.Value = Val(TextBox1.Value) + Val(TextBox2.Value)
End Sub
 

Ben S

Board Regular
Joined
Oct 21, 2002
Messages
124

ADVERTISEMENT

For some reason i have to type a number in the field to enable the textbox to populate with the answer.

Is there a way of automatically populating the textbox with no manual intervention
 

pmdown

Board Regular
Joined
May 6, 2002
Messages
71
Yes.

E.g. you may use the "AfterUpdate" event and calculate or other process values in other TextBoxes...
 

Ben S

Board Regular
Joined
Oct 21, 2002
Messages
124
Sorry

I have only started to use Userforms in the last week.

How would i achieve this?
 

pmdown

Board Regular
Joined
May 6, 2002
Messages
71
Hi.

In VBE (Visual Basic Editor) double click on TextBox2. Empty code shows. In dropDown (Up-Right) select "AfterUpdate" Event and add code like This:

----------------------------------
Private Sub TextBox2_AfterUpdate()
TextBox3.Value = Val(TextBox1.Value) + Val(TextBox2.Value)
End Sub
----------------------------------

Run forms, and whenever You changes value in TextBox2 - Value in TextBox3 automaticaly will be recalculated.

Same code You may attach for TextBox1 too...
 

Forum statistics

Threads
1,143,613
Messages
5,719,713
Members
422,242
Latest member
hishamkhatri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top